@api-client/core 0.19.18 → 0.19.19
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/build/src/browser.d.ts +1 -1
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js.map +1 -1
- package/build/src/mocking/lib/Organization.d.ts +5 -1
- package/build/src/mocking/lib/Organization.d.ts.map +1 -1
- package/build/src/mocking/lib/Organization.js +17 -0
- package/build/src/mocking/lib/Organization.js.map +1 -1
- package/build/src/models/store/Organization.d.ts +13 -0
- package/build/src/models/store/Organization.d.ts.map +1 -1
- package/build/src/models/store/Organization.js.map +1 -1
- package/build/src/sdk/OrganizationsSdk.d.ts +17 -1
- package/build/src/sdk/OrganizationsSdk.d.ts.map +1 -1
- package/build/src/sdk/OrganizationsSdk.js +76 -0
- package/build/src/sdk/OrganizationsSdk.js.map +1 -1
- package/build/src/sdk/RouteBuilder.d.ts +2 -0
- package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
- package/build/src/sdk/RouteBuilder.js +6 -0
- package/build/src/sdk/RouteBuilder.js.map +1 -1
- package/build/src/sdk/SdkMock.d.ts +12 -0
- package/build/src/sdk/SdkMock.d.ts.map +1 -1
- package/build/src/sdk/SdkMock.js +32 -0
- package/build/src/sdk/SdkMock.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/mocking/lib/Organization.ts +22 -1
- package/src/models/store/Organization.ts +14 -0
- package/src/sdk/OrganizationsSdk.ts +81 -1
- package/src/sdk/RouteBuilder.ts +8 -0
- package/src/sdk/SdkMock.ts +50 -0
package/package.json
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { faker } from '@faker-js/faker'
|
|
2
2
|
import { OrganizationKind } from '../../models/kinds.js'
|
|
3
3
|
import { nanoid } from '../../nanoid.js'
|
|
4
|
-
import type { OrganizationSchema } from '../../models/store/Organization.js'
|
|
4
|
+
import type { OrganizationSchema, OrganizationSlugValidateResponse } from '../../models/store/Organization.js'
|
|
5
5
|
|
|
6
6
|
export class Organization {
|
|
7
|
+
organizationSlugGenerateResponse(name?: string): { slug: string } {
|
|
8
|
+
const finalName = name ?? faker.company.name()
|
|
9
|
+
let baseSlug = faker.helpers.slugify(finalName)
|
|
10
|
+
// Truncate to ensure there's room for a suffix if needed
|
|
11
|
+
if (baseSlug.length > 55) {
|
|
12
|
+
baseSlug = baseSlug.substring(0, 55)
|
|
13
|
+
}
|
|
14
|
+
const suffix = nanoid(6).toLowerCase()
|
|
15
|
+
return { slug: `${baseSlug}-${suffix}` }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
organizationSlugValidateResponse(
|
|
19
|
+
init: Partial<OrganizationSlugValidateResponse> = {}
|
|
20
|
+
): OrganizationSlugValidateResponse {
|
|
21
|
+
const { valid = true, reason } = init
|
|
22
|
+
return {
|
|
23
|
+
valid,
|
|
24
|
+
reason,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
7
28
|
/**
|
|
8
29
|
* Generates a random organization object.
|
|
9
30
|
* @param init Optional values to be present in the object.
|
|
@@ -4,6 +4,20 @@ import { OrganizationKind } from '../kinds.js'
|
|
|
4
4
|
|
|
5
5
|
export type UserOrganizationGrantType = 'owner' | 'manager' | 'editor' | 'viewer'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* The response of the organization slug validation.
|
|
9
|
+
*/
|
|
10
|
+
export interface OrganizationSlugValidateResponse {
|
|
11
|
+
/**
|
|
12
|
+
* Whether the slug is valid.
|
|
13
|
+
*/
|
|
14
|
+
valid: boolean
|
|
15
|
+
/**
|
|
16
|
+
* The reason why the slug is invalid.
|
|
17
|
+
*/
|
|
18
|
+
reason?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
7
21
|
/**
|
|
8
22
|
* In the system the user identity represents registration information associated with a specific identity provider.
|
|
9
23
|
* This association allows the user to use different identity providers that map to the same user, as long as the
|
|
@@ -8,7 +8,11 @@ import {
|
|
|
8
8
|
} from './SdkBase.js'
|
|
9
9
|
import { RouteBuilder } from './RouteBuilder.js'
|
|
10
10
|
import type { ContextListOptions, ContextListResult } from '../events/BaseEvents.js'
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
OrganizationSchema,
|
|
13
|
+
UserOrganizationGrantType,
|
|
14
|
+
OrganizationSlugValidateResponse,
|
|
15
|
+
} from '../models/store/Organization.js'
|
|
12
16
|
import type { InvitationSchema } from '../models/store/Invitation.js'
|
|
13
17
|
import type { PatchInfo } from '../patch/types.js'
|
|
14
18
|
import type { UserSchema } from '../models/store/User.js'
|
|
@@ -520,4 +524,80 @@ export class OrganizationsSdk extends SdkBase {
|
|
|
520
524
|
}
|
|
521
525
|
},
|
|
522
526
|
}
|
|
527
|
+
|
|
528
|
+
slugs = {
|
|
529
|
+
/**
|
|
530
|
+
* Generates a slug for the organization.
|
|
531
|
+
* @param name The name of the organization.
|
|
532
|
+
* @param request Optional request options.
|
|
533
|
+
* @returns A promise that resolves to the generated slug.
|
|
534
|
+
*/
|
|
535
|
+
generate: async (name: string, request: SdkOptions = {}): Promise<string> => {
|
|
536
|
+
const { token } = request
|
|
537
|
+
const url = this.sdk.getUrl(RouteBuilder.orgSlugGenerate()).toString()
|
|
538
|
+
const body = {
|
|
539
|
+
name,
|
|
540
|
+
}
|
|
541
|
+
const result = await this.sdk.http.post(url, {
|
|
542
|
+
body: JSON.stringify(body),
|
|
543
|
+
token,
|
|
544
|
+
})
|
|
545
|
+
this.inspectCommonStatusCodes(result)
|
|
546
|
+
const E_PREFIX = 'Unable to generate the slug. '
|
|
547
|
+
if (result.status !== 200) {
|
|
548
|
+
this.logInvalidResponse(result)
|
|
549
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
550
|
+
}
|
|
551
|
+
if (!result.body) {
|
|
552
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
553
|
+
}
|
|
554
|
+
let data: { slug: string }
|
|
555
|
+
try {
|
|
556
|
+
data = JSON.parse(result.body)
|
|
557
|
+
} catch {
|
|
558
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
559
|
+
}
|
|
560
|
+
if (!data.slug) {
|
|
561
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
562
|
+
}
|
|
563
|
+
return data.slug
|
|
564
|
+
},
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Validates a slug for the organization.
|
|
568
|
+
* @param slug The slug to validate.
|
|
569
|
+
* @param request Optional request options.
|
|
570
|
+
* @returns A promise that resolves to the validation result.
|
|
571
|
+
*/
|
|
572
|
+
validate: async (slug: string, request: SdkOptions = {}): Promise<OrganizationSlugValidateResponse> => {
|
|
573
|
+
const { token } = request
|
|
574
|
+
const url = this.sdk.getUrl(RouteBuilder.orgSlugValidate()).toString()
|
|
575
|
+
const body = {
|
|
576
|
+
slug,
|
|
577
|
+
}
|
|
578
|
+
const result = await this.sdk.http.post(url, {
|
|
579
|
+
body: JSON.stringify(body),
|
|
580
|
+
token,
|
|
581
|
+
})
|
|
582
|
+
this.inspectCommonStatusCodes(result)
|
|
583
|
+
const E_PREFIX = 'Unable to validate the slug. '
|
|
584
|
+
if (result.status !== 200) {
|
|
585
|
+
this.logInvalidResponse(result)
|
|
586
|
+
throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body)
|
|
587
|
+
}
|
|
588
|
+
if (!result.body) {
|
|
589
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status })
|
|
590
|
+
}
|
|
591
|
+
let data: OrganizationSlugValidateResponse
|
|
592
|
+
try {
|
|
593
|
+
data = JSON.parse(result.body)
|
|
594
|
+
} catch {
|
|
595
|
+
throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status })
|
|
596
|
+
}
|
|
597
|
+
if (typeof data.valid !== 'boolean') {
|
|
598
|
+
throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status })
|
|
599
|
+
}
|
|
600
|
+
return data
|
|
601
|
+
},
|
|
602
|
+
}
|
|
523
603
|
}
|
package/src/sdk/RouteBuilder.ts
CHANGED
|
@@ -326,4 +326,12 @@ export class RouteBuilder {
|
|
|
326
326
|
static aiMessage(oid: string, sid: string, mid: string): string {
|
|
327
327
|
return `${RouteBuilder.aiMessages(oid, sid)}/${mid}`
|
|
328
328
|
}
|
|
329
|
+
|
|
330
|
+
static orgSlugGenerate(): string {
|
|
331
|
+
return `/v1/orgs/slugs/generate`
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
static orgSlugValidate(): string {
|
|
335
|
+
return `/v1/orgs/slugs/validate`
|
|
336
|
+
}
|
|
329
337
|
}
|
package/src/sdk/SdkMock.ts
CHANGED
|
@@ -591,6 +591,56 @@ export class SdkMock {
|
|
|
591
591
|
)
|
|
592
592
|
},
|
|
593
593
|
},
|
|
594
|
+
|
|
595
|
+
slugs: {
|
|
596
|
+
/**
|
|
597
|
+
* Mocks the `slugs.validate()` method.
|
|
598
|
+
* @param options Optional response customization.
|
|
599
|
+
*/
|
|
600
|
+
validate: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
|
|
601
|
+
const { mock } = this
|
|
602
|
+
const respond = this.createDefaultResponse(
|
|
603
|
+
200,
|
|
604
|
+
{ 'content-type': 'application/json' },
|
|
605
|
+
() => JSON.stringify(this.gen.organization.organizationSlugValidateResponse()),
|
|
606
|
+
init
|
|
607
|
+
)
|
|
608
|
+
await mock.add(
|
|
609
|
+
{
|
|
610
|
+
match: {
|
|
611
|
+
uri: RouteBuilder.orgSlugValidate(),
|
|
612
|
+
methods: ['POST'],
|
|
613
|
+
},
|
|
614
|
+
respond,
|
|
615
|
+
},
|
|
616
|
+
options
|
|
617
|
+
)
|
|
618
|
+
},
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Mocks the `slugs.generate()` method.
|
|
622
|
+
* @param options Optional response customization.
|
|
623
|
+
*/
|
|
624
|
+
generate: async (init?: MockResult, options?: InterceptOptions): Promise<void> => {
|
|
625
|
+
const { mock } = this
|
|
626
|
+
const respond = this.createDefaultResponse(
|
|
627
|
+
200,
|
|
628
|
+
{ 'content-type': 'application/json' },
|
|
629
|
+
() => JSON.stringify(this.gen.organization.organizationSlugGenerateResponse()),
|
|
630
|
+
init
|
|
631
|
+
)
|
|
632
|
+
await mock.add(
|
|
633
|
+
{
|
|
634
|
+
match: {
|
|
635
|
+
uri: RouteBuilder.orgSlugGenerate(),
|
|
636
|
+
methods: ['POST'],
|
|
637
|
+
},
|
|
638
|
+
respond,
|
|
639
|
+
},
|
|
640
|
+
options
|
|
641
|
+
)
|
|
642
|
+
},
|
|
643
|
+
},
|
|
594
644
|
}
|
|
595
645
|
|
|
596
646
|
/**
|