@rippling/rippling-sdk 0.2.0-alpha.85 → 0.2.0-alpha.86
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/core/platform/custom-objects/category.d.mts +125 -0
- package/core/platform/custom-objects/category.d.mts.map +1 -0
- package/core/platform/custom-objects/category.d.ts +125 -0
- package/core/platform/custom-objects/category.d.ts.map +1 -0
- package/core/platform/custom-objects/category.js +188 -0
- package/core/platform/custom-objects/category.js.map +1 -0
- package/core/platform/custom-objects/category.mjs +178 -0
- package/core/platform/custom-objects/category.mjs.map +1 -0
- package/core/platform/custom-objects/definition.d.mts +147 -0
- package/core/platform/custom-objects/definition.d.mts.map +1 -0
- package/core/platform/custom-objects/definition.d.ts +147 -0
- package/core/platform/custom-objects/definition.d.ts.map +1 -0
- package/core/platform/custom-objects/definition.js +200 -0
- package/core/platform/custom-objects/definition.js.map +1 -0
- package/core/platform/custom-objects/definition.mjs +190 -0
- package/core/platform/custom-objects/definition.mjs.map +1 -0
- package/core/platform/custom-objects/fields.d.mts +302 -0
- package/core/platform/custom-objects/fields.d.mts.map +1 -0
- package/core/platform/custom-objects/fields.d.ts +302 -0
- package/core/platform/custom-objects/fields.d.ts.map +1 -0
- package/core/platform/custom-objects/fields.js +369 -0
- package/core/platform/custom-objects/fields.js.map +1 -0
- package/core/platform/custom-objects/fields.mjs +347 -0
- package/core/platform/custom-objects/fields.mjs.map +1 -0
- package/core/platform/custom-objects/function-runtime.d.mts +42 -0
- package/core/platform/custom-objects/function-runtime.d.mts.map +1 -0
- package/core/platform/custom-objects/function-runtime.d.ts +42 -0
- package/core/platform/custom-objects/function-runtime.d.ts.map +1 -0
- package/core/platform/custom-objects/function-runtime.js +38 -0
- package/core/platform/custom-objects/function-runtime.js.map +1 -0
- package/core/platform/custom-objects/function-runtime.mjs +35 -0
- package/core/platform/custom-objects/function-runtime.mjs.map +1 -0
- package/core/platform/custom-objects/lifecycle.d.mts +83 -0
- package/core/platform/custom-objects/lifecycle.d.mts.map +1 -0
- package/core/platform/custom-objects/lifecycle.d.ts +83 -0
- package/core/platform/custom-objects/lifecycle.d.ts.map +1 -0
- package/core/platform/custom-objects/lifecycle.js +372 -0
- package/core/platform/custom-objects/lifecycle.js.map +1 -0
- package/core/platform/custom-objects/lifecycle.mjs +367 -0
- package/core/platform/custom-objects/lifecycle.mjs.map +1 -0
- package/core/platform/custom-objects/manager.d.mts +354 -0
- package/core/platform/custom-objects/manager.d.mts.map +1 -0
- package/core/platform/custom-objects/manager.d.ts +354 -0
- package/core/platform/custom-objects/manager.d.ts.map +1 -0
- package/core/platform/custom-objects/manager.js +646 -0
- package/core/platform/custom-objects/manager.js.map +1 -0
- package/core/platform/custom-objects/manager.mjs +637 -0
- package/core/platform/custom-objects/manager.mjs.map +1 -0
- package/core/platform/custom-objects/provisioning.d.mts +138 -0
- package/core/platform/custom-objects/provisioning.d.mts.map +1 -0
- package/core/platform/custom-objects/provisioning.d.ts +138 -0
- package/core/platform/custom-objects/provisioning.d.ts.map +1 -0
- package/core/platform/custom-objects/provisioning.js +455 -0
- package/core/platform/custom-objects/provisioning.js.map +1 -0
- package/core/platform/custom-objects/provisioning.mjs +447 -0
- package/core/platform/custom-objects/provisioning.mjs.map +1 -0
- package/core/platform/custom-objects/rql.d.mts +122 -0
- package/core/platform/custom-objects/rql.d.mts.map +1 -0
- package/core/platform/custom-objects/rql.d.ts +122 -0
- package/core/platform/custom-objects/rql.d.ts.map +1 -0
- package/core/platform/custom-objects/rql.js +225 -0
- package/core/platform/custom-objects/rql.js.map +1 -0
- package/core/platform/custom-objects/rql.mjs +222 -0
- package/core/platform/custom-objects/rql.mjs.map +1 -0
- package/core/platform/custom-objects/schema-manager.d.mts +203 -0
- package/core/platform/custom-objects/schema-manager.d.mts.map +1 -0
- package/core/platform/custom-objects/schema-manager.d.ts +203 -0
- package/core/platform/custom-objects/schema-manager.d.ts.map +1 -0
- package/core/platform/custom-objects/schema-manager.js +256 -0
- package/core/platform/custom-objects/schema-manager.js.map +1 -0
- package/core/platform/custom-objects/schema-manager.mjs +249 -0
- package/core/platform/custom-objects/schema-manager.mjs.map +1 -0
- package/core/platform/custom-objects/typed-rql.d.mts +157 -0
- package/core/platform/custom-objects/typed-rql.d.mts.map +1 -0
- package/core/platform/custom-objects/typed-rql.d.ts +157 -0
- package/core/platform/custom-objects/typed-rql.d.ts.map +1 -0
- package/core/platform/custom-objects/typed-rql.js +583 -0
- package/core/platform/custom-objects/typed-rql.js.map +1 -0
- package/core/platform/custom-objects/typed-rql.mjs +580 -0
- package/core/platform/custom-objects/typed-rql.mjs.map +1 -0
- package/core/platform/custom-objects/types.d.mts +549 -0
- package/core/platform/custom-objects/types.d.mts.map +1 -0
- package/core/platform/custom-objects/types.d.ts +549 -0
- package/core/platform/custom-objects/types.d.ts.map +1 -0
- package/core/platform/custom-objects/types.js +20 -0
- package/core/platform/custom-objects/types.js.map +1 -0
- package/core/platform/custom-objects/types.mjs +17 -0
- package/core/platform/custom-objects/types.mjs.map +1 -0
- package/core/platform/custom-objects/validation.d.mts +97 -0
- package/core/platform/custom-objects/validation.d.mts.map +1 -0
- package/core/platform/custom-objects/validation.d.ts +97 -0
- package/core/platform/custom-objects/validation.d.ts.map +1 -0
- package/core/platform/custom-objects/validation.js +477 -0
- package/core/platform/custom-objects/validation.js.map +1 -0
- package/core/platform/custom-objects/validation.mjs +465 -0
- package/core/platform/custom-objects/validation.mjs.map +1 -0
- package/core/platform/custom-objects.d.mts +67 -0
- package/core/platform/custom-objects.d.mts.map +1 -0
- package/core/platform/custom-objects.d.ts +67 -0
- package/core/platform/custom-objects.d.ts.map +1 -0
- package/core/platform/custom-objects.js +118 -0
- package/core/platform/custom-objects.js.map +1 -0
- package/core/platform/custom-objects.mjs +45 -0
- package/core/platform/custom-objects.mjs.map +1 -0
- package/package.json +1 -1
- package/resources/custom-objects/custom-objects.d.mts +7 -0
- package/resources/custom-objects/custom-objects.d.mts.map +1 -1
- package/resources/custom-objects/custom-objects.d.ts +7 -0
- package/resources/custom-objects/custom-objects.d.ts.map +1 -1
- package/resources/custom-objects/custom-objects.js.map +1 -1
- package/resources/custom-objects/custom-objects.mjs.map +1 -1
- package/resources/custom-objects/fields.d.mts +129 -54
- package/resources/custom-objects/fields.d.mts.map +1 -1
- package/resources/custom-objects/fields.d.ts +129 -54
- package/resources/custom-objects/fields.d.ts.map +1 -1
- package/resources/levels.d.mts +25 -4
- package/resources/levels.d.mts.map +1 -1
- package/resources/levels.d.ts +25 -4
- package/resources/levels.d.ts.map +1 -1
- package/src/core/platform/custom-objects/category.ts +294 -0
- package/src/core/platform/custom-objects/definition.ts +373 -0
- package/src/core/platform/custom-objects/fields.ts +653 -0
- package/src/core/platform/custom-objects/function-runtime.ts +76 -0
- package/src/core/platform/custom-objects/lifecycle.ts +557 -0
- package/src/core/platform/custom-objects/manager.ts +959 -0
- package/src/core/platform/custom-objects/provisioning.ts +672 -0
- package/src/core/platform/custom-objects/rql.ts +375 -0
- package/src/core/platform/custom-objects/schema-manager.ts +351 -0
- package/src/core/platform/custom-objects/typed-rql.ts +1273 -0
- package/src/core/platform/custom-objects/types.ts +753 -0
- package/src/core/platform/custom-objects/validation.ts +573 -0
- package/src/core/platform/custom-objects.ts +269 -0
- package/src/resources/custom-objects/custom-objects.ts +8 -0
- package/src/resources/custom-objects/fields.ts +192 -59
- package/src/resources/levels.ts +28 -4
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import type { RipplingSDK } from '../../../client';
|
|
2
|
+
import type {
|
|
3
|
+
ObjectCategory,
|
|
4
|
+
ObjectCategoryCreateParams,
|
|
5
|
+
ObjectCategoryUpdateParams,
|
|
6
|
+
} from '../../../resources/object-categories';
|
|
7
|
+
import type { CategoryApiName, LogicalCategoryName } from './types';
|
|
8
|
+
import { toCustomCategoryApiName } from './definition';
|
|
9
|
+
import { validateLogicalCategoryName } from './validation';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Author input accepted by {@link defineCustomObjectCategory}.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam TName - Logical category name supplied by the caller.
|
|
15
|
+
*/
|
|
16
|
+
interface CustomObjectCategoryDefinitionInput<TName extends string> {
|
|
17
|
+
/** Logical unsuffixed snake_case category name. */
|
|
18
|
+
readonly name: LogicalCategoryName<TName>;
|
|
19
|
+
/** Human-readable display name applied after creation. */
|
|
20
|
+
readonly displayName: string;
|
|
21
|
+
/** Optional category description. */
|
|
22
|
+
readonly description?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Immutable typed category definition used by provisioning and lifecycle helpers. */
|
|
26
|
+
export interface CustomObjectCategoryDefinition<TName extends LogicalCategoryName = LogicalCategoryName> {
|
|
27
|
+
/** Logical unsuffixed snake_case category name. */
|
|
28
|
+
readonly name: TName;
|
|
29
|
+
/** Compiled wire-level category api name. */
|
|
30
|
+
readonly apiName: CategoryApiName<TName>;
|
|
31
|
+
/** Human-readable display name. */
|
|
32
|
+
readonly displayName: string;
|
|
33
|
+
/** Optional category description. */
|
|
34
|
+
readonly description?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Result returned by category provisioning helpers. */
|
|
38
|
+
export interface ProvisionedCustomObjectCategory<TName extends LogicalCategoryName = LogicalCategoryName> {
|
|
39
|
+
/** Source typed category definition. */
|
|
40
|
+
readonly definition: CustomObjectCategoryDefinition<TName>;
|
|
41
|
+
/** Response returned by `client.objectCategories.create(...)`. */
|
|
42
|
+
readonly createdCategory: ObjectCategory;
|
|
43
|
+
/** Response returned by `client.objectCategories.update(...)`. */
|
|
44
|
+
readonly updatedCategory: ObjectCategory;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Lifecycle action emitted by category reconciliation helpers. */
|
|
48
|
+
export type CustomObjectCategoryLifecycleAction = 'created' | 'updated' | 'unchanged';
|
|
49
|
+
|
|
50
|
+
/** Result returned by category reconciliation helpers. */
|
|
51
|
+
export interface ReconciledCustomObjectCategory<TName extends LogicalCategoryName = LogicalCategoryName> {
|
|
52
|
+
/** Source typed category definition. */
|
|
53
|
+
readonly definition: CustomObjectCategoryDefinition<TName>;
|
|
54
|
+
/** Whether the remote category was created, updated, or already matched. */
|
|
55
|
+
readonly action: CustomObjectCategoryLifecycleAction;
|
|
56
|
+
/** Remote category after reconciliation. */
|
|
57
|
+
readonly category: ObjectCategory;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Options for category provisioning and reconciliation helpers. */
|
|
61
|
+
export interface CustomObjectCategoryMutationOptions {
|
|
62
|
+
/** Whether to apply the follow-up display-metadata update. Defaults to `true`. */
|
|
63
|
+
readonly updateDisplayMetadata?: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Creates an immutable typed custom-object category definition.
|
|
68
|
+
*
|
|
69
|
+
* @param definition - Logical category metadata to normalize and freeze.
|
|
70
|
+
* @returns Immutable typed category definition with compiled API name.
|
|
71
|
+
* @typeParam TName - Logical category name supplied by the caller.
|
|
72
|
+
*/
|
|
73
|
+
export function defineCustomObjectCategory<TName extends string>(
|
|
74
|
+
definition: CustomObjectCategoryDefinitionInput<TName>,
|
|
75
|
+
): Readonly<CustomObjectCategoryDefinition<LogicalCategoryName<TName>>> {
|
|
76
|
+
validateLogicalCategoryName(definition.name);
|
|
77
|
+
return Object.freeze({
|
|
78
|
+
name: definition.name,
|
|
79
|
+
apiName: toCustomCategoryApiName(definition.name),
|
|
80
|
+
displayName: definition.displayName,
|
|
81
|
+
...(definition.description != null ? { description: definition.description } : {}),
|
|
82
|
+
}) as Readonly<CustomObjectCategoryDefinition<LogicalCategoryName<TName>>>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Builds the low-level create payload for an object category.
|
|
87
|
+
*
|
|
88
|
+
* @param definition - Typed category definition to compile.
|
|
89
|
+
* @returns REST create payload using the logical category name.
|
|
90
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
91
|
+
*/
|
|
92
|
+
export function buildObjectCategoryCreateParams<TName extends LogicalCategoryName>(
|
|
93
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
94
|
+
): ObjectCategoryCreateParams {
|
|
95
|
+
return {
|
|
96
|
+
name: definition.name,
|
|
97
|
+
...(definition.description != null ? { description: definition.description } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Builds the low-level update payload for an object category.
|
|
103
|
+
*
|
|
104
|
+
* @param definition - Typed category definition to compile.
|
|
105
|
+
* @returns REST update payload using human-facing display metadata.
|
|
106
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
107
|
+
*/
|
|
108
|
+
export function buildObjectCategoryUpdateParams<TName extends LogicalCategoryName>(
|
|
109
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
110
|
+
): ObjectCategoryUpdateParams {
|
|
111
|
+
return {
|
|
112
|
+
name: definition.displayName,
|
|
113
|
+
...(definition.description != null ? { description: definition.description } : {}),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns whether one public category DTO matches the typed category definition by currently visible names.
|
|
119
|
+
*
|
|
120
|
+
* @param category - Public category DTO returned by the REST API.
|
|
121
|
+
* @param definition - Typed category definition being matched.
|
|
122
|
+
* @returns Whether the visible name matches either the logical or display name.
|
|
123
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
124
|
+
*/
|
|
125
|
+
function isMatchingCategoryName<TName extends LogicalCategoryName>(
|
|
126
|
+
category: ObjectCategory,
|
|
127
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
128
|
+
): boolean {
|
|
129
|
+
return category.name === definition.name || category.name === definition.displayName;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Lists all public category DTOs that ambiguously or exactly match one typed definition.
|
|
134
|
+
*
|
|
135
|
+
* @param client - SDK client used to enumerate categories.
|
|
136
|
+
* @param definition - Typed category definition being matched.
|
|
137
|
+
* @returns Frozen list of public categories whose visible names match.
|
|
138
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
139
|
+
*/
|
|
140
|
+
async function listMatchingCategories<TName extends LogicalCategoryName>(
|
|
141
|
+
client: RipplingSDK,
|
|
142
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
143
|
+
): Promise<readonly ObjectCategory[]> {
|
|
144
|
+
const matches: ObjectCategory[] = [];
|
|
145
|
+
for await (const category of client.objectCategories.list()) {
|
|
146
|
+
if (isMatchingCategoryName(category, definition)) {
|
|
147
|
+
matches.push(category);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return Object.freeze(matches);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns the single public category matching one typed definition or throws when the match is ambiguous.
|
|
155
|
+
*
|
|
156
|
+
* @param client - SDK client used to enumerate categories.
|
|
157
|
+
* @param definition - Typed category definition being matched.
|
|
158
|
+
* @returns Matching public category, if any.
|
|
159
|
+
* @throws Error when multiple public categories match the visible names.
|
|
160
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
161
|
+
*/
|
|
162
|
+
async function getSingleMatchingCategory<TName extends LogicalCategoryName>(
|
|
163
|
+
client: RipplingSDK,
|
|
164
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
165
|
+
): Promise<ObjectCategory | undefined> {
|
|
166
|
+
const matches = await listMatchingCategories(client, definition);
|
|
167
|
+
if (matches.length <= 1) return matches[0];
|
|
168
|
+
|
|
169
|
+
throw new Error(
|
|
170
|
+
`Ambiguous category match for "${definition.name}" / "${definition.displayName}". ` +
|
|
171
|
+
`Matched ids: ${matches.map((category) => category.id).join(', ')}.`,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Creates one typed custom-object category through the REST SDK.
|
|
177
|
+
*
|
|
178
|
+
* @param client - SDK client used to call the category APIs.
|
|
179
|
+
* @param definition - Typed category definition to provision.
|
|
180
|
+
* @param options - Provisioning behavior flags for display-metadata updates.
|
|
181
|
+
* @returns Frozen summary of the created and updated backend category DTOs.
|
|
182
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
183
|
+
*/
|
|
184
|
+
export async function provisionCustomObjectCategoryDefinition<TName extends LogicalCategoryName>(
|
|
185
|
+
client: RipplingSDK,
|
|
186
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
187
|
+
options: CustomObjectCategoryMutationOptions = {},
|
|
188
|
+
): Promise<ProvisionedCustomObjectCategory<TName>> {
|
|
189
|
+
const createdCategory = await client.objectCategories.create(buildObjectCategoryCreateParams(definition));
|
|
190
|
+
const updatedCategory =
|
|
191
|
+
options.updateDisplayMetadata ?? true ?
|
|
192
|
+
await client.objectCategories.update(createdCategory.id, buildObjectCategoryUpdateParams(definition))
|
|
193
|
+
: createdCategory;
|
|
194
|
+
|
|
195
|
+
return Object.freeze({ definition, createdCategory, updatedCategory });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Creates multiple typed custom-object categories through the REST SDK.
|
|
200
|
+
*
|
|
201
|
+
* @param client - SDK client used to call the category APIs.
|
|
202
|
+
* @param definitions - Typed category definitions to provision.
|
|
203
|
+
* @param options - Provisioning behavior flags shared across the batch.
|
|
204
|
+
* @returns Frozen batch of provisioning results in input order.
|
|
205
|
+
*/
|
|
206
|
+
export async function provisionCustomObjectCategoryDefinitions(
|
|
207
|
+
client: RipplingSDK,
|
|
208
|
+
definitions: readonly CustomObjectCategoryDefinition[],
|
|
209
|
+
options: CustomObjectCategoryMutationOptions = {},
|
|
210
|
+
): Promise<readonly ProvisionedCustomObjectCategory[]> {
|
|
211
|
+
const results: ProvisionedCustomObjectCategory[] = [];
|
|
212
|
+
for (const definition of definitions) {
|
|
213
|
+
results.push(await provisionCustomObjectCategoryDefinition(client, definition, options));
|
|
214
|
+
}
|
|
215
|
+
return Object.freeze(results);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Reconciles one typed category definition against the backend by name.
|
|
220
|
+
*
|
|
221
|
+
* @param client - SDK client used to call the category APIs.
|
|
222
|
+
* @param definition - Typed category definition to reconcile.
|
|
223
|
+
* @param options - Reconciliation behavior flags for display-metadata updates.
|
|
224
|
+
* @returns Frozen reconciliation result describing the final backend category state.
|
|
225
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
226
|
+
*/
|
|
227
|
+
export async function reconcileCustomObjectCategoryDefinition<TName extends LogicalCategoryName>(
|
|
228
|
+
client: RipplingSDK,
|
|
229
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
230
|
+
options: CustomObjectCategoryMutationOptions = {},
|
|
231
|
+
): Promise<ReconciledCustomObjectCategory<TName>> {
|
|
232
|
+
const existing = await getSingleMatchingCategory(client, definition);
|
|
233
|
+
if (existing == null) {
|
|
234
|
+
const provisioned = await provisionCustomObjectCategoryDefinition(client, definition, options);
|
|
235
|
+
return Object.freeze({
|
|
236
|
+
definition,
|
|
237
|
+
action: 'created' as const,
|
|
238
|
+
category: provisioned.updatedCategory,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const shouldUpdate =
|
|
243
|
+
(options.updateDisplayMetadata ?? true) &&
|
|
244
|
+
(existing.name !== definition.displayName ||
|
|
245
|
+
(existing.description ?? '') !== (definition.description ?? ''));
|
|
246
|
+
|
|
247
|
+
if (!shouldUpdate) {
|
|
248
|
+
return Object.freeze({ definition, action: 'unchanged', category: existing });
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const updated = await client.objectCategories.update(
|
|
252
|
+
existing.id,
|
|
253
|
+
buildObjectCategoryUpdateParams(definition),
|
|
254
|
+
);
|
|
255
|
+
return Object.freeze({ definition, action: 'updated', category: updated });
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Reconciles multiple typed category definitions against the backend by name.
|
|
260
|
+
*
|
|
261
|
+
* @param client - SDK client used to call the category APIs.
|
|
262
|
+
* @param definitions - Typed category definitions to reconcile.
|
|
263
|
+
* @param options - Reconciliation behavior flags shared across the batch.
|
|
264
|
+
* @returns Frozen batch of reconciliation results in input order.
|
|
265
|
+
*/
|
|
266
|
+
export async function reconcileCustomObjectCategoryDefinitions(
|
|
267
|
+
client: RipplingSDK,
|
|
268
|
+
definitions: readonly CustomObjectCategoryDefinition[],
|
|
269
|
+
options: CustomObjectCategoryMutationOptions = {},
|
|
270
|
+
): Promise<readonly ReconciledCustomObjectCategory[]> {
|
|
271
|
+
const results: ReconciledCustomObjectCategory[] = [];
|
|
272
|
+
for (const definition of definitions) {
|
|
273
|
+
results.push(await reconcileCustomObjectCategoryDefinition(client, definition, options));
|
|
274
|
+
}
|
|
275
|
+
return Object.freeze(results);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Deletes a category that matches the typed definition's logical or display name.
|
|
280
|
+
*
|
|
281
|
+
* @param client - SDK client used to call the category APIs.
|
|
282
|
+
* @param definition - Typed category definition used to find the category to delete.
|
|
283
|
+
* @returns Whether a matching category existed and was deleted.
|
|
284
|
+
* @typeParam TName - Logical category name carried by the definition.
|
|
285
|
+
*/
|
|
286
|
+
export async function deleteCustomObjectCategoryDefinition<TName extends LogicalCategoryName>(
|
|
287
|
+
client: RipplingSDK,
|
|
288
|
+
definition: CustomObjectCategoryDefinition<TName>,
|
|
289
|
+
): Promise<boolean> {
|
|
290
|
+
const existing = await getSingleMatchingCategory(client, definition);
|
|
291
|
+
if (existing == null) return false;
|
|
292
|
+
await client.objectCategories.delete(existing.id);
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import type { CustomObjectCategoryDefinition } from './category';
|
|
2
|
+
import type {
|
|
3
|
+
AnyCustomObjectDefinition,
|
|
4
|
+
AnyFieldDefinition,
|
|
5
|
+
CategoryApiName,
|
|
6
|
+
CustomObjectApiName,
|
|
7
|
+
CustomObjectDefinition,
|
|
8
|
+
FieldDefinitions,
|
|
9
|
+
FieldNames,
|
|
10
|
+
LogicalCategoryName,
|
|
11
|
+
LogicalCustomFieldName,
|
|
12
|
+
LogicalCustomObjectName,
|
|
13
|
+
NameFieldDefinition,
|
|
14
|
+
ResolvedFieldDefinition,
|
|
15
|
+
SectionDefinitions,
|
|
16
|
+
} from './types';
|
|
17
|
+
import {
|
|
18
|
+
validateCustomObjectDefinition,
|
|
19
|
+
validateLogicalCategoryName,
|
|
20
|
+
validateLogicalCustomFieldName,
|
|
21
|
+
validateLogicalCustomObjectName,
|
|
22
|
+
} from './validation';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Internal input shape accepted by {@link defineCustomObject} before normalization.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam TObjectName - Logical custom-object name for the definition.
|
|
28
|
+
* @typeParam TCategoryName - Logical category name associated with the object.
|
|
29
|
+
* @typeParam TSections - Section map available to field definitions.
|
|
30
|
+
* @typeParam TFields - Field map keyed by logical custom-field names.
|
|
31
|
+
* @typeParam TNameField - Optional name-field behavior supplied by the caller.
|
|
32
|
+
*/
|
|
33
|
+
type CategoryInput<TCategoryName extends string> =
|
|
34
|
+
| LogicalCategoryName<TCategoryName>
|
|
35
|
+
| CustomObjectCategoryDefinition<LogicalCategoryName<TCategoryName>>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Internal input shape accepted by {@link defineCustomObject} before normalization.
|
|
39
|
+
*
|
|
40
|
+
* @typeParam TObjectName - Logical custom-object name for the definition.
|
|
41
|
+
* @typeParam TCategoryName - Logical category name associated with the object.
|
|
42
|
+
* @typeParam TSections - Section map available to field definitions.
|
|
43
|
+
* @typeParam TFields - Field map keyed by logical custom-field names.
|
|
44
|
+
* @typeParam TNameField - Optional name-field behavior supplied by the caller.
|
|
45
|
+
*/
|
|
46
|
+
interface CustomObjectDefinitionInput<
|
|
47
|
+
TObjectName extends string,
|
|
48
|
+
TCategoryName extends string,
|
|
49
|
+
TSections extends SectionDefinitions,
|
|
50
|
+
TFields extends FieldDefinitions,
|
|
51
|
+
TNameField extends NameFieldDefinition,
|
|
52
|
+
> {
|
|
53
|
+
readonly name: LogicalCustomObjectName<TObjectName>;
|
|
54
|
+
readonly displayName: string;
|
|
55
|
+
readonly pluralLabel?: string;
|
|
56
|
+
readonly category: CategoryInput<TCategoryName>;
|
|
57
|
+
readonly ownerRole?: string;
|
|
58
|
+
readonly enableHistory?: boolean;
|
|
59
|
+
readonly description: string;
|
|
60
|
+
readonly icon?: {
|
|
61
|
+
readonly emoji?: string | null;
|
|
62
|
+
readonly ripplingIcon?: string | null;
|
|
63
|
+
readonly s3Bucket?: string;
|
|
64
|
+
readonly s3Key?: string;
|
|
65
|
+
};
|
|
66
|
+
readonly nameField?: TNameField;
|
|
67
|
+
readonly sections?: TSections;
|
|
68
|
+
readonly fields: ValidateFieldMap<TFields>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Rejects extension objects that try to redefine keys already present on the base definition.
|
|
73
|
+
*
|
|
74
|
+
* @typeParam TExisting - Existing key set on the base definition.
|
|
75
|
+
* @typeParam TAdded - Proposed extension object.
|
|
76
|
+
*/
|
|
77
|
+
type NoOverlappingKeys<TExisting extends object, TAdded extends object> = Extract<
|
|
78
|
+
keyof TExisting,
|
|
79
|
+
keyof TAdded
|
|
80
|
+
> extends never ?
|
|
81
|
+
TAdded
|
|
82
|
+
: never;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Converts a logical field map into a version whose keys must all satisfy the
|
|
86
|
+
* logical custom-field name contract.
|
|
87
|
+
*
|
|
88
|
+
* @typeParam TFields - Candidate logical field map supplied by callers.
|
|
89
|
+
*/
|
|
90
|
+
type ValidateFieldMap<TFields extends FieldDefinitions> = {
|
|
91
|
+
readonly [K in keyof TFields]: K extends string ?
|
|
92
|
+
LogicalCustomFieldName<K> extends never ?
|
|
93
|
+
never
|
|
94
|
+
: TFields[K]
|
|
95
|
+
: never;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Recursively freezes author-authored schema definitions.
|
|
100
|
+
*
|
|
101
|
+
* The schema layer is intended to act like durable configuration data rather
|
|
102
|
+
* than mutable runtime state, so this helper aggressively removes mutation as a
|
|
103
|
+
* failure mode after validation succeeds.
|
|
104
|
+
*
|
|
105
|
+
* @typeParam T - Value being frozen.
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* Deeply freezes a schema fragment after validation succeeds.
|
|
109
|
+
*
|
|
110
|
+
* @param value - Value to recursively freeze in place.
|
|
111
|
+
* @returns The same value, now deeply frozen where applicable.
|
|
112
|
+
* @typeParam T - Value being frozen.
|
|
113
|
+
*/
|
|
114
|
+
function deepFreeze<T>(value: T): T {
|
|
115
|
+
if (value == null || typeof value !== 'object') return value;
|
|
116
|
+
|
|
117
|
+
for (const child of Object.values(value as Record<string, unknown>)) {
|
|
118
|
+
deepFreeze(child);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return Object.freeze(value);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Appends the platform-required `__c` suffix to a logical custom-object name.
|
|
126
|
+
*
|
|
127
|
+
* @param name - Logical unsuffixed custom-object name.
|
|
128
|
+
* @returns Wire-level custom-object API name with the required `__c` suffix.
|
|
129
|
+
* @typeParam TObjectName - Logical custom-object name to compile.
|
|
130
|
+
*/
|
|
131
|
+
export function toCustomObjectApiName<TObjectName extends string>(
|
|
132
|
+
name: LogicalCustomObjectName<TObjectName>,
|
|
133
|
+
): CustomObjectApiName<TObjectName> {
|
|
134
|
+
return `${name}__c` as CustomObjectApiName<TObjectName>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Appends the platform-required `__c` suffix to a logical custom-field name.
|
|
139
|
+
*
|
|
140
|
+
* @param name - Logical unsuffixed custom-field name.
|
|
141
|
+
* @returns Wire-level custom-field API name with the required `__c` suffix.
|
|
142
|
+
* @typeParam TFieldName - Logical custom-field name to compile.
|
|
143
|
+
*/
|
|
144
|
+
export function toCustomFieldApiName<TFieldName extends string>(
|
|
145
|
+
name: LogicalCustomFieldName<TFieldName>,
|
|
146
|
+
): `${TFieldName}__c` {
|
|
147
|
+
return `${name}__c`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Appends the platform-required `__c` suffix to a logical category name.
|
|
152
|
+
*
|
|
153
|
+
* @param name - Logical unsuffixed category name.
|
|
154
|
+
* @returns Wire-level category API name with the required `__c` suffix.
|
|
155
|
+
* @typeParam TCategoryName - Logical category name to compile.
|
|
156
|
+
*/
|
|
157
|
+
export function toCustomCategoryApiName<TCategoryName extends string>(
|
|
158
|
+
name: LogicalCategoryName<TCategoryName>,
|
|
159
|
+
): CategoryApiName<TCategoryName> {
|
|
160
|
+
return `${name}__c` as CategoryApiName<TCategoryName>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Defines an immutable, strongly typed custom-object schema.
|
|
165
|
+
*
|
|
166
|
+
* Callers author only logical snake_case names. The returned value includes the
|
|
167
|
+
* derived wire-level api names so downstream tooling can emit valid manifest
|
|
168
|
+
* payloads without requiring authors to know about the `__c` suffix contract.
|
|
169
|
+
*
|
|
170
|
+
* @typeParam TObjectName - Logical custom-object name for the definition.
|
|
171
|
+
* @typeParam TCategoryName - Logical category name associated with the object.
|
|
172
|
+
* @typeParam TSections - Section map available to field definitions.
|
|
173
|
+
* @typeParam TFields - Field map keyed by logical custom-field names.
|
|
174
|
+
* @param definition - Author-facing typed schema definition to normalize, validate, and freeze.
|
|
175
|
+
* @returns Immutable normalized custom-object definition with compiled field and object API names.
|
|
176
|
+
* @typeParam TNameField - Name-field behavior for the object.
|
|
177
|
+
*/
|
|
178
|
+
export function defineCustomObject<
|
|
179
|
+
TObjectName extends string,
|
|
180
|
+
TCategoryName extends string,
|
|
181
|
+
TSections extends SectionDefinitions = {},
|
|
182
|
+
TFields extends FieldDefinitions = FieldDefinitions,
|
|
183
|
+
TNameField extends NameFieldDefinition = { kind: 'text' },
|
|
184
|
+
>(
|
|
185
|
+
definition: CustomObjectDefinitionInput<TObjectName, TCategoryName, TSections, TFields, TNameField>,
|
|
186
|
+
): Readonly<
|
|
187
|
+
CustomObjectDefinition<
|
|
188
|
+
LogicalCustomObjectName<TObjectName>,
|
|
189
|
+
LogicalCategoryName<TCategoryName>,
|
|
190
|
+
TSections,
|
|
191
|
+
TFields,
|
|
192
|
+
TNameField
|
|
193
|
+
>
|
|
194
|
+
> {
|
|
195
|
+
validateLogicalCustomObjectName(definition.name);
|
|
196
|
+
|
|
197
|
+
const categoryDefinition = typeof definition.category === 'string' ? undefined : definition.category;
|
|
198
|
+
const categoryName =
|
|
199
|
+
typeof definition.category === 'string' ? definition.category : definition.category.name;
|
|
200
|
+
const categoryApiName =
|
|
201
|
+
typeof definition.category === 'string' ?
|
|
202
|
+
toCustomCategoryApiName(definition.category)
|
|
203
|
+
: definition.category.apiName;
|
|
204
|
+
|
|
205
|
+
validateLogicalCategoryName(categoryName);
|
|
206
|
+
|
|
207
|
+
const resolvedFields = Object.fromEntries(
|
|
208
|
+
Object.entries(definition.fields).map(([logicalName, field]) => {
|
|
209
|
+
validateLogicalCustomFieldName(logicalName);
|
|
210
|
+
return [
|
|
211
|
+
logicalName,
|
|
212
|
+
{
|
|
213
|
+
...field,
|
|
214
|
+
logicalName,
|
|
215
|
+
apiName: toCustomFieldApiName(logicalName),
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
}),
|
|
219
|
+
) as unknown as {
|
|
220
|
+
readonly [K in Extract<keyof TFields, string>]: ResolvedFieldDefinition<K, TFields[K]>;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const normalized = {
|
|
224
|
+
name: definition.name,
|
|
225
|
+
apiName: toCustomObjectApiName(definition.name) as CustomObjectApiName<
|
|
226
|
+
LogicalCustomObjectName<TObjectName>
|
|
227
|
+
>,
|
|
228
|
+
displayName: definition.displayName,
|
|
229
|
+
...(definition.pluralLabel != null ? { pluralLabel: definition.pluralLabel } : {}),
|
|
230
|
+
category: categoryName,
|
|
231
|
+
...(categoryDefinition != null ? { categoryDefinition } : {}),
|
|
232
|
+
...(definition.ownerRole != null ? { ownerRole: definition.ownerRole } : {}),
|
|
233
|
+
...(definition.enableHistory != null ? { enableHistory: definition.enableHistory } : {}),
|
|
234
|
+
categoryApiName: categoryApiName as CategoryApiName<LogicalCategoryName<TCategoryName>>,
|
|
235
|
+
description: definition.description,
|
|
236
|
+
...(definition.icon != null ? { icon: definition.icon } : {}),
|
|
237
|
+
nameField: (definition.nameField ?? { kind: 'text' }) as TNameField,
|
|
238
|
+
sections: (definition.sections ?? ({} as TSections)) as TSections,
|
|
239
|
+
fields: resolvedFields,
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const issues = validateCustomObjectDefinition(normalized as unknown as AnyCustomObjectDefinition);
|
|
243
|
+
if (issues.length > 0) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`Invalid custom object definition for "${definition.name}":\n` +
|
|
246
|
+
issues.map((issue) => `- ${issue.path}: ${issue.message}`).join('\n'),
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return deepFreeze(normalized) as Readonly<
|
|
251
|
+
CustomObjectDefinition<
|
|
252
|
+
LogicalCustomObjectName<TObjectName>,
|
|
253
|
+
LogicalCategoryName<TCategoryName>,
|
|
254
|
+
TSections,
|
|
255
|
+
TFields,
|
|
256
|
+
TNameField
|
|
257
|
+
>
|
|
258
|
+
>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Extends an existing object definition without losing type information.
|
|
263
|
+
*
|
|
264
|
+
* This helper is useful when a platform package wants to publish a base schema
|
|
265
|
+
* and another package wants to add fields or sections in a type-safe way.
|
|
266
|
+
*
|
|
267
|
+
* @typeParam TBase - Existing object definition being extended.
|
|
268
|
+
* @typeParam TAddedSections - New section definitions merged into the base object.
|
|
269
|
+
* @param base - Existing typed object definition to extend.
|
|
270
|
+
* @param extension - Additional metadata, sections, and fields to merge into the base definition.
|
|
271
|
+
* @returns New immutable custom-object definition preserving the combined type information.
|
|
272
|
+
* @typeParam TAddedFields - New field definitions merged into the base object.
|
|
273
|
+
*/
|
|
274
|
+
export function extendCustomObject<
|
|
275
|
+
TBase extends AnyCustomObjectDefinition,
|
|
276
|
+
TAddedSections extends SectionDefinitions = {},
|
|
277
|
+
TAddedFields extends FieldDefinitions = {},
|
|
278
|
+
>(
|
|
279
|
+
base: TBase,
|
|
280
|
+
extension: {
|
|
281
|
+
readonly displayName?: string;
|
|
282
|
+
readonly pluralLabel?: string;
|
|
283
|
+
readonly ownerRole?: string;
|
|
284
|
+
readonly enableHistory?: boolean;
|
|
285
|
+
readonly description?: string;
|
|
286
|
+
readonly icon?: TBase['icon'];
|
|
287
|
+
readonly sections?: NoOverlappingKeys<TBase['sections'], TAddedSections>;
|
|
288
|
+
readonly fields?: NoOverlappingKeys<TBase['fields'], ValidateFieldMap<TAddedFields>>;
|
|
289
|
+
},
|
|
290
|
+
): Readonly<
|
|
291
|
+
CustomObjectDefinition<
|
|
292
|
+
TBase['name'],
|
|
293
|
+
TBase['category'],
|
|
294
|
+
TBase['sections'] & TAddedSections,
|
|
295
|
+
Omit<TBase['fields'], never> & TAddedFields,
|
|
296
|
+
TBase['nameField']
|
|
297
|
+
>
|
|
298
|
+
> {
|
|
299
|
+
const mergedSections = {
|
|
300
|
+
...base.sections,
|
|
301
|
+
...(extension.sections ?? {}),
|
|
302
|
+
} as TBase['sections'] & TAddedSections;
|
|
303
|
+
|
|
304
|
+
const mergedFields = Object.fromEntries(
|
|
305
|
+
Object.entries({ ...base.fields, ...(extension.fields ?? {}) }).map(([logicalName, field]) => [
|
|
306
|
+
logicalName,
|
|
307
|
+
{
|
|
308
|
+
...field,
|
|
309
|
+
logicalName,
|
|
310
|
+
apiName: toCustomFieldApiName(logicalName as LogicalCustomFieldName<string>),
|
|
311
|
+
},
|
|
312
|
+
]),
|
|
313
|
+
) as unknown as Omit<TBase['fields'], never> & TAddedFields;
|
|
314
|
+
|
|
315
|
+
return defineCustomObject({
|
|
316
|
+
name: base.name,
|
|
317
|
+
displayName: extension.displayName ?? base.displayName,
|
|
318
|
+
...(extension.pluralLabel != null || base.pluralLabel != null ?
|
|
319
|
+
{ pluralLabel: extension.pluralLabel ?? base.pluralLabel }
|
|
320
|
+
: {}),
|
|
321
|
+
...(extension.ownerRole != null || base.ownerRole != null ?
|
|
322
|
+
{ ownerRole: extension.ownerRole ?? base.ownerRole }
|
|
323
|
+
: {}),
|
|
324
|
+
...(extension.enableHistory != null || base.enableHistory != null ?
|
|
325
|
+
{ enableHistory: extension.enableHistory ?? base.enableHistory }
|
|
326
|
+
: {}),
|
|
327
|
+
category: base.categoryDefinition ?? base.category,
|
|
328
|
+
description: extension.description ?? base.description,
|
|
329
|
+
...((extension.icon ?? base.icon) != null ? { icon: extension.icon ?? base.icon } : {}),
|
|
330
|
+
nameField: base.nameField,
|
|
331
|
+
sections: mergedSections,
|
|
332
|
+
fields: mergedFields as ValidateFieldMap<Omit<TBase['fields'], never> & TAddedFields>,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Returns the logical custom field names defined on an object.
|
|
338
|
+
*
|
|
339
|
+
* @param definition - Object definition whose logical field names should be returned.
|
|
340
|
+
* @returns Frozen array of logical field names from the definition.
|
|
341
|
+
* @typeParam TDefinition - Object definition whose field names should be returned.
|
|
342
|
+
*/
|
|
343
|
+
export function fieldNames<TDefinition extends AnyCustomObjectDefinition>(
|
|
344
|
+
definition: TDefinition,
|
|
345
|
+
): ReadonlyArray<FieldNames<TDefinition>> {
|
|
346
|
+
return Object.freeze(Object.keys(definition.fields) as FieldNames<TDefinition>[]);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Retrieves a field definition by logical field name with precise typing.
|
|
351
|
+
*
|
|
352
|
+
* @param definition - Object definition that owns the field.
|
|
353
|
+
* @param fieldName - Logical field name to retrieve.
|
|
354
|
+
* @returns Precisely typed field definition for the requested logical field name.
|
|
355
|
+
* @typeParam TDefinition - Object definition that owns the field.
|
|
356
|
+
* @typeParam TFieldName - Logical field name being retrieved.
|
|
357
|
+
*/
|
|
358
|
+
export function getFieldDefinition<
|
|
359
|
+
TDefinition extends AnyCustomObjectDefinition,
|
|
360
|
+
TFieldName extends FieldNames<TDefinition>,
|
|
361
|
+
>(definition: TDefinition, fieldName: TFieldName): TDefinition['fields'][TFieldName] {
|
|
362
|
+
return (definition.fields as Record<string, unknown>)[fieldName] as TDefinition['fields'][TFieldName];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Returns whether one typed field definition is writable by record create/update helpers.
|
|
367
|
+
*
|
|
368
|
+
* @param field - Typed field definition to inspect.
|
|
369
|
+
* @returns Whether the field may be written by callers.
|
|
370
|
+
*/
|
|
371
|
+
export function isWritableField(field: AnyFieldDefinition): boolean {
|
|
372
|
+
return field.writable;
|
|
373
|
+
}
|