export type PartialV5RuleYamlV5IonRuleLocalDuration = {day?: number | undefined, hour?: number | undefined, minute?: number | undefined, month?: number | undefined, quarter?: number | undefined, second?: number | undefined, week?: number | undefined, year?: number | undefined}; export type PartialV5RuleYamlV5IonRuleUnit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second'; export type PartialV5RuleYamlV5IonRuleDuration = {year: number} | {quarter: number} | {month: number} | {week: number} | {day: number} | {hour: number} | {minute: number} | {second: number}; export type PartialV5RuleYamlV5IonRuleValueOperator = {not: boolean, rightValue: {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'GreaterEqual'} | {duration: PartialV5RuleYamlV5IonRuleDuration, from: {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, not: boolean, reverse: boolean, type: 'TimeRange'} | {from: {unit: PartialV5RuleYamlV5IonRuleUnit}, not: false, type: 'TimeRange'} | {type: 'TimeToday'} | {from: {unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'TimeThis'} | {from: {unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'TimeNext'} | {type: 'TimeWithinNext', unit: PartialV5RuleYamlV5IonRuleUnit, value: string} | {type: 'TimeWithinPast', unit: PartialV5RuleYamlV5IonRuleUnit, value: string} | {from: {next: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, not: false, to: {next: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'TimeInBetweenNext'} | {not: boolean, rightValue: {timestamp: string}, type: 'Equal'} | {not: false, rightValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'Greater'} | {not: false, rightValue: {timestamp: string}, type: 'GreaterEqual'} | {not: false, rightValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'Less'} | {not: false, rightValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'LessEqual'} | {maxValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, minValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, not: boolean, type: 'Between'} | {not: boolean, rightValue: number | string | boolean, type: 'Equal'} | {not: boolean, rightValue: number | string | boolean, type: 'IsNull'} | {not: boolean, rightValues: Array, type: 'In'} | {not: boolean, rightValue: number | string | boolean, type: 'Greater'} | {not: boolean, rightValue: number | string | boolean, type: 'Less'} | {not: boolean, rightValue: number | string | boolean, type: 'GreaterEqual'} | {not: boolean, rightValue: number | string | boolean, type: 'LessEqual'} | {maxValue: number | string, minValue: number | string, not: boolean, rightValue: number, type: 'Between'} | {not: boolean, rightValues: Array, type: 'Contain'} | {not: boolean, rightValues: Array, type: 'StartWith'} | {not: boolean, rightValues: Array, type: 'EndWith'} | {not: boolean, rightValue: string, type: 'Regexp'}; export type PartialV5RuleYamlV5IonRuleReferenceCondition = {exclude: boolean, id: string, type: 'FunnelStageReference' | 'Reference' | 'AbTestVariantReference'} | {id: string, includeConvertedCustomers: boolean, maxGrade: number, minGrade: number, type: 'PredictiveScoreReference'} | {id: string, leftValue: {attribute: 'r_quartile' | 'f_quartile' | 'm_quartile' | 'rfm_segment' | 'rfm_score' | 'rfm_cluster_rank' | 'rfm_quartile'}, operator: PartialV5RuleYamlV5IonRuleValueOperator, solutionType: 'rfm', type: 'MlAttributeReference'} | {id: string, leftValue: {attribute: 'cltv_1m' | 'cltv_1m_pctile' | 'cltv_3m' | 'cltv_3m_pctile' | 'cltv_6m' | 'cltv_6m_pctile' | 'cltv_12m' | 'cltv_12m_pctile' | 'cltv_24m' | 'cltv_24m_pctile' | 'alive_prob' | 'cltv_segment'}, operator: PartialV5RuleYamlV5IonRuleValueOperator, solutionType: 'cltv', type: 'MlAttributeReference'}; export type PartialV5RuleYamlV5IonRuleValueArrayMatching = unknown | 'all' | 'any' | {atLeast: number} | {atMost: number} | {exactly: number}; export type PartialV5RuleYamlV5IonRuleAttributeNameValue = {name: string}; export type PartialV5RuleYamlV5IonRuleCustomerGroupAttributeValue = {customerGroup: string, name: string}; export type PartialV5RuleYamlV5IonRuleTimeframeOperator = {not: boolean, rightValue: {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'GreaterEqual'} | {duration: PartialV5RuleYamlV5IonRuleDuration, from: {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, not: boolean, reverse: boolean, type: 'TimeRange'} | {from: {unit: PartialV5RuleYamlV5IonRuleUnit}, not: false, type: 'TimeRange'} | {type: 'TimeToday'} | {from: {unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'TimeThis'} | {from: {unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'TimeNext'} | {type: 'TimeWithinNext', unit: PartialV5RuleYamlV5IonRuleUnit, value: string} | {type: 'TimeWithinPast', unit: PartialV5RuleYamlV5IonRuleUnit, value: string} | {from: {next: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, not: false, to: {next: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'TimeInBetweenNext'} | {not: boolean, rightValue: {timestamp: string}, type: 'Equal'} | {not: false, rightValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'Greater'} | {not: false, rightValue: {timestamp: string}, type: 'GreaterEqual'} | {not: false, rightValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'Less'} | {not: false, rightValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, type: 'LessEqual'} | {maxValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, minValue: {timestamp: string} | {last: number | PartialV5RuleYamlV5IonRuleLocalDuration, unit: PartialV5RuleYamlV5IonRuleUnit}, not: boolean, type: 'Between'}; export type PartialV5RuleYamlV5IonRuleColumnFilter = {arrayMatching: PartialV5RuleYamlV5IonRuleValueArrayMatching, column: string, operator: PartialV5RuleYamlV5IonRuleValueOperator, type: 'Column'} | {arrayMatching: PartialV5RuleYamlV5IonRuleValueArrayMatching, column: 'timestamp', operator: PartialV5RuleYamlV5IonRuleTimeframeOperator, type: 'Column'}; export type PartialV5RuleYamlV5IonRuleOrFilter = {conditions: Array, type: 'Or'}; export type PartialV5RuleYamlV5IonRuleAndFilter = {conditions: Array, type: 'And'}; export type PartialV5RuleYamlV5IonRuleFilter = Record | null | PartialV5RuleYamlV5IonRuleAndFilter | PartialV5RuleYamlV5IonRuleOrFilter; export type PartialV5RuleYamlV5IonRuleAggregationValue = {aggregation: {column: string, groupingColumns?: Array | undefined, type: 'Sum' | 'Min' | 'Max' | 'Average'} | {groupingColumns: Array, type: 'Count'} | {columns: Array, type: 'CountDistinct'} | {column: string, groupingColumns?: Array | undefined, orderColumn: string, type: 'First' | 'Last'}, filter: PartialV5RuleYamlV5IonRuleFilter, source: {name: string}, window?: ({duration: {day?: number | undefined, hour?: number | undefined, minute?: number | undefined, second?: number | undefined}, type: 'TimeSliding'}) | undefined}; export type PartialV5RuleYamlV5IonRuleValueLeftValue = PartialV5RuleYamlV5IonRuleAttributeNameValue | PartialV5RuleYamlV5IonRuleCustomerGroupAttributeValue | PartialV5RuleYamlV5IonRuleAggregationValue; export type PartialV5RuleYamlV5IonRuleValueLimit = {number: number, orderColumns?: (Array<{column: string, order: 'ascending' | 'descending', type: 'Column'} | {order: 'ascending' | 'descending', type: 'Aggregation'}>) | undefined, type: 'Count' | 'Percent'}; export type PartialV5RuleYamlV5IonRuleValueCondition = {arrayMatching: PartialV5RuleYamlV5IonRuleValueArrayMatching, exclude: boolean, leftValue: PartialV5RuleYamlV5IonRuleValueLeftValue, limit?: PartialV5RuleYamlV5IonRuleValueLimit | undefined, operator: PartialV5RuleYamlV5IonRuleValueOperator, type: 'Value'}; export type PartialV5RuleYamlV5IonRuleValueConditionSet = {conditions: Array, description?: string | undefined, expr?: string | undefined, type: 'Or' | 'And' | 'Composite'}; export type PartialV5RuleYamlV5IonRuleIonRule = {conditions: Array, expr?: string | undefined, limit?: PartialV5RuleYamlV5IonRuleValueLimit | undefined, type: 'Or' | 'And' | 'Composite'}; export type PartialV5RuleYamlV5IonRule = PartialV5RuleYamlV5IonRuleIonRule | Record | null; export type SegmentParameters = {audienceId?: number | undefined, name?: string | undefined, realtime?: boolean | undefined, kind?: number | undefined, funnel_stage?: ({funnel_id?: number | undefined, stage_id?: number | undefined}) | undefined, description?: string | undefined, segmentFolderId?: number | undefined, rule?: PartialV5RuleYamlV5IonRule | undefined, countPopulation?: boolean | undefined}; export type CreateApiAudiencesAudienceIdSegmentsArgs = {audienceId: number, body: SegmentParameters}; export type CreateApiAudiencesAudienceIdSegmentsOptions = {baseUrl?: string | undefined, TdApikeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create new segment * * POST /audiences/{audienceId}/segments */ export const createApiAudiencesAudienceIdSegments = async (args: CreateApiAudiencesAudienceIdSegmentsArgs, options?: CreateApiAudiencesAudienceIdSegmentsOptions) => { const {baseUrl = "https://api-cdp.treasuredata.com", fetch: fetchFn = fetch, TdApikeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (TdApikeyAuth !== undefined) headers.set("Authorization", TdApikeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/audiences/${encodeURIComponent(String(args.audienceId))}/segments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };