@segment/actions-core
Advanced tools
Comparing version
@@ -8,3 +8,3 @@ "use strict"; | ||
return treatNullAsEmpty ? [] : value; | ||
if ((0, real_type_of_1.isArray)(value)) | ||
if (real_type_of_1.isArray(value)) | ||
return value; | ||
@@ -15,3 +15,3 @@ return [value]; | ||
function arrifyFields(obj, schema = {}) { | ||
if (!(0, real_type_of_1.isObject)(obj)) { | ||
if (!real_type_of_1.isObject(obj)) { | ||
return obj; | ||
@@ -18,0 +18,0 @@ } |
@@ -6,3 +6,3 @@ import { AllRequestOptions, RequestOptions } from './request-client'; | ||
} | ||
export type RequestClient = ReturnType<typeof createRequestClient>; | ||
export default function createRequestClient(...requestOptions: AllRequestOptions[]): <Data = unknown>(url: string, options?: RequestOptions) => Promise<ModifiedResponse<Data>>; | ||
export declare type RequestClient = ReturnType<typeof createRequestClient>; | ||
export default function createRequestClient(...requestOptions: AllRequestOptions[]): <Data = unknown>(url: string, options?: RequestOptions | undefined) => Promise<ModifiedResponse<Data>>; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -33,3 +29,3 @@ if (k2 === undefined) k2 = k; | ||
const request_client_1 = __importStar(require("./request-client")); | ||
const baseClient = (0, request_client_1.default)({ | ||
const baseClient = request_client_1.default({ | ||
timeout: request_client_1.DEFAULT_REQUEST_TIMEOUT, | ||
@@ -36,0 +32,0 @@ headers: { |
@@ -33,3 +33,3 @@ "use strict"; | ||
event: 'Test Event', | ||
messageId: (0, uuid_1.v4)(), | ||
messageId: uuid_1.v4(), | ||
properties: {}, | ||
@@ -36,0 +36,0 @@ receivedAt: new Date().toISOString(), |
@@ -22,7 +22,7 @@ "use strict"; | ||
const fields = this.definition.actions[action].fields; | ||
const defaultMappings = (0, map_values_1.mapValues)(fields, 'default'); | ||
const defaultMappings = map_values_1.mapValues(fields, 'default'); | ||
mapping = { ...defaultMappings, ...mapping }; | ||
} | ||
this.results = await super.executeAction(action, { | ||
event: (0, create_test_event_1.createTestEvent)(event), | ||
event: create_test_event_1.createTestEvent(event), | ||
mapping, | ||
@@ -48,3 +48,3 @@ settings: settings ?? {}, | ||
const fields = this.definition.actions[action].fields; | ||
const defaultMappings = (0, map_values_1.mapValues)(fields, 'default'); | ||
const defaultMappings = map_values_1.mapValues(fields, 'default'); | ||
mapping = { ...defaultMappings, ...mapping }; | ||
@@ -56,3 +56,3 @@ } | ||
const batchResponse = await super.executeBatch(action, { | ||
events: events.map((event) => (0, create_test_event_1.createTestEvent)(event)), | ||
events: events.map((event) => create_test_event_1.createTestEvent(event)), | ||
mapping, | ||
@@ -59,0 +59,0 @@ settings: settings ?? {}, |
@@ -10,5 +10,5 @@ /// <reference types="node" /> | ||
import { Logger, StatsContext, TransactionContext, StateContext, EngageDestinationCache, SubscriptionMetadata } from './index'; | ||
type MaybePromise<T> = T | Promise<T>; | ||
type RequestClient = ReturnType<typeof createRequestClient>; | ||
export type RequestFn<Settings, Payload, Return = any, AudienceSettings = any, ActionHookInputs = any> = (request: RequestClient, data: ExecuteInput<Settings, Payload, AudienceSettings, ActionHookInputs>) => MaybePromise<Return>; | ||
declare type MaybePromise<T> = T | Promise<T>; | ||
declare type RequestClient = ReturnType<typeof createRequestClient>; | ||
export declare type RequestFn<Settings, Payload, Return = any, AudienceSettings = any, ActionHookInputs = any> = (request: RequestClient, data: ExecuteInput<Settings, Payload, AudienceSettings, ActionHookInputs>) => MaybePromise<Return>; | ||
export interface BaseActionDefinition { | ||
@@ -22,5 +22,5 @@ title: string; | ||
} | ||
type HookValueTypes = string | boolean | number | Array<string | boolean | number>; | ||
type GenericActionHookValues = Record<string, HookValueTypes>; | ||
type GenericActionHookBundle = { | ||
declare type HookValueTypes = string | boolean | number | Array<string | boolean | number>; | ||
declare type GenericActionHookValues = Record<string, HookValueTypes>; | ||
declare type GenericActionHookBundle = { | ||
[K in ActionHookType]?: { | ||
@@ -31,4 +31,4 @@ inputs?: GenericActionHookValues; | ||
}; | ||
type IsArray<T> = T extends (infer U)[] ? U : never; | ||
type PerformBatchResponse = MaybePromise<MultiStatusResponse> | MaybePromise<unknown>; | ||
declare type IsArray<T> = T extends (infer U)[] ? U : never; | ||
declare type PerformBatchResponse = MaybePromise<MultiStatusResponse> | MaybePromise<unknown>; | ||
export interface ActionDefinition<Settings, Payload = any, AudienceSettings = any, GeneratedActionHookBundle extends GenericActionHookBundle = any> extends BaseActionDefinition { | ||
@@ -50,3 +50,3 @@ dynamicFields?: { | ||
export declare const hookTypeStrings: readonly ["onMappingSave", "retlOnMappingSave"]; | ||
export type ActionHookType = typeof hookTypeStrings[number]; | ||
export declare type ActionHookType = typeof hookTypeStrings[number]; | ||
export interface ActionHookResponse<GeneratedActionHookOutputs> { | ||
@@ -53,0 +53,0 @@ successMessage?: string; |
@@ -37,3 +37,3 @@ "use strict"; | ||
if (Object.keys(definition.fields ?? {}).length) { | ||
this.schema = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(definition.fields); | ||
this.schema = fields_to_jsonschema_1.fieldsToJsonSchema(definition.fields); | ||
} | ||
@@ -63,3 +63,3 @@ if (definition.hooks) { | ||
} | ||
this.hookSchemas[hookName] = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(castedInputFields); | ||
this.hookSchemas[hookName] = fields_to_jsonschema_1.fieldsToJsonSchema(castedInputFields); | ||
} | ||
@@ -72,8 +72,8 @@ } | ||
const mapping = removeInternalHiddenFields(bundle.mapping); | ||
let payload = (0, mapping_kit_1.transform)(mapping, bundle.data); | ||
let payload = mapping_kit_1.transform(mapping, bundle.data); | ||
results.push({ output: 'Mappings resolved' }); | ||
payload = (0, remove_empty_values_1.removeEmptyValues)(payload, this.schema, true); | ||
payload = remove_empty_values_1.removeEmptyValues(payload, this.schema, true); | ||
if (this.schema) { | ||
const schemaKey = `${this.destinationName}:${this.definition.title}`; | ||
(0, schema_validation_1.validateSchema)(payload, this.schema, { | ||
schema_validation_1.validateSchema(payload, this.schema, { | ||
schemaKey, | ||
@@ -123,3 +123,3 @@ statsContext: bundle.statsContext, | ||
const mapping = removeInternalHiddenFields(bundle.mapping); | ||
let payloads = (0, mapping_kit_1.transformBatch)(mapping, bundle.data); | ||
let payloads = mapping_kit_1.transformBatch(mapping, bundle.data); | ||
const batchPayloadLength = payloads.length; | ||
@@ -139,5 +139,5 @@ const multiStatusResponse = []; | ||
for (let i = 0; i < payloads.length; i++) { | ||
const payload = (0, remove_empty_values_1.removeEmptyValues)(payloads[i], schema); | ||
const payload = remove_empty_values_1.removeEmptyValues(payloads[i], schema); | ||
try { | ||
(0, schema_validation_1.validateSchema)(payload, schema, validationOptions); | ||
schema_validation_1.validateSchema(payload, schema, validationOptions); | ||
} | ||
@@ -292,3 +292,3 @@ catch (e) { | ||
const { dynamicHandlerPath, dynamicFieldContext } = this.extractFieldContextAndHandler(field); | ||
const fn = (0, get_1.get)(this.definition.dynamicFields, dynamicHandlerPath); | ||
const fn = get_1.get(this.definition.dynamicFields, dynamicHandlerPath); | ||
if (typeof fn !== 'function') { | ||
@@ -316,3 +316,3 @@ return Promise.resolve({ | ||
const schema = this.hookSchemas[hookType]; | ||
(0, schema_validation_1.validateSchema)(data.hookInputs, schema, { | ||
schema_validation_1.validateSchema(data.hookInputs, schema, { | ||
exempt: ['dynamicAuthSettings'] | ||
@@ -330,3 +330,3 @@ }); | ||
const options = this.extendRequest?.(data) ?? {}; | ||
return (0, create_request_client_1.default)(options, { | ||
return create_request_client_1.default(options, { | ||
afterResponse: [this.afterResponse.bind(this)], | ||
@@ -378,3 +378,3 @@ statsContext: data.statsContext | ||
if (!this.data.errortype) { | ||
this.data.errortype = (0, errors_1.getErrorCodeFromHttpStatus)(this.data.status); | ||
this.data.errortype = errors_1.getErrorCodeFromHttpStatus(this.data.status); | ||
} | ||
@@ -381,0 +381,0 @@ } |
import { JSONSchema4 } from 'json-schema'; | ||
import type { InputField, GlobalSetting, Optional } from './types'; | ||
export type MinimalInputField = Optional<InputField, 'description'> | (Optional<GlobalSetting, 'description'> & { | ||
import type { InputField, GlobalSetting, Optional, DependsOnConditions, Condition } from './types'; | ||
export declare type MinimalInputField = Optional<InputField, 'description'> | (Optional<GlobalSetting, 'description'> & { | ||
additionalProperties?: boolean; | ||
}); | ||
export type MinimalFields = Record<string, MinimalInputField>; | ||
export declare type MinimalFields = Record<string, MinimalInputField>; | ||
interface SchemaOptions { | ||
tsType?: boolean; | ||
additionalProperties?: boolean; | ||
omitRequiredSchemas?: boolean; | ||
} | ||
export declare function fieldsToJsonSchema(fields?: MinimalFields, options?: SchemaOptions): JSONSchema4; | ||
export declare function fieldConditionSingleDependencyToJsonSchema(condition: Condition, fieldKey: string): JSONSchema4; | ||
export declare function singleFieldConditionsToJsonSchema(fieldKey: string, singleFieldConditions: DependsOnConditions): JSONSchema4 | undefined; | ||
export declare function conditionsToJsonSchema(allFieldConditions: Record<string, DependsOnConditions>): JSONSchema4; | ||
export declare function fieldsToJsonSchema(fields?: MinimalFields, options?: SchemaOptions, additionalSchema?: JSONSchema4): JSONSchema4; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fieldsToJsonSchema = void 0; | ||
exports.fieldsToJsonSchema = exports.conditionsToJsonSchema = exports.singleFieldConditionsToJsonSchema = exports.fieldConditionSingleDependencyToJsonSchema = void 0; | ||
function toJsonSchemaType(type) { | ||
@@ -16,5 +16,162 @@ switch (type) { | ||
} | ||
function fieldsToJsonSchema(fields = {}, options) { | ||
const fieldKeyIsDotNotation = (fieldKey) => { | ||
return fieldKey.split('.').length > 1; | ||
}; | ||
const generateThenStatement = (fieldKey) => { | ||
if (fieldKeyIsDotNotation(fieldKey)) { | ||
const [parentKey, childKey] = fieldKey.split('.'); | ||
return { | ||
required: [parentKey], | ||
properties: { | ||
[parentKey]: { | ||
required: [childKey] | ||
} | ||
} | ||
}; | ||
} | ||
return { | ||
required: [fieldKey] | ||
}; | ||
}; | ||
const undefinedConditionValueToJSONSchema = (dependantFieldKey, fieldKey, operator, multiple) => { | ||
if (operator !== 'is' && operator !== 'is_not') { | ||
throw new Error(`Unsupported conditionally required field operator: ${operator}`); | ||
} | ||
const insideIfStatement = operator === 'is' ? { not: { required: [dependantFieldKey] } } : { required: [dependantFieldKey] }; | ||
if (multiple) { | ||
return insideIfStatement; | ||
} | ||
if (operator === 'is') { | ||
const fieldIsNull = { properties: { [dependantFieldKey]: { type: 'null' } } }; | ||
return { | ||
if: { anyOf: [insideIfStatement, fieldIsNull] }, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
} | ||
const fieldIsNotNull = { not: { properties: { [dependantFieldKey]: { type: 'null' } } } }; | ||
return { | ||
if: { allOf: [insideIfStatement, fieldIsNotNull] }, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
}; | ||
const simpleConditionToJSONSchema = (dependantFieldKey, fieldKey, dependantValue, operator, multiple) => { | ||
const dependantValueToJSONSchema = operator === 'is' ? { const: dependantValue } : { not: { const: dependantValue } }; | ||
if (multiple) { | ||
return { | ||
properties: { [dependantFieldKey]: dependantValueToJSONSchema }, | ||
required: [dependantFieldKey] | ||
}; | ||
} | ||
return { | ||
if: { | ||
properties: { [dependantFieldKey]: dependantValueToJSONSchema } | ||
}, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
}; | ||
const objectConditionToJSONSchema = (objectParentKey, objectChildKey, fieldKey, dependantValue, operator, multiple) => { | ||
const dependantValueToJSONSchema = operator === 'is' ? { const: dependantValue } : { not: { const: dependantValue } }; | ||
if (multiple) { | ||
return { | ||
properties: { | ||
[objectParentKey]: { properties: { [objectChildKey]: dependantValueToJSONSchema }, required: [objectChildKey] } | ||
}, | ||
required: [objectParentKey] | ||
}; | ||
} | ||
return { | ||
if: { | ||
properties: { | ||
[objectParentKey]: { properties: { [objectChildKey]: dependantValueToJSONSchema }, required: [objectChildKey] } | ||
}, | ||
required: [objectParentKey] | ||
}, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
}; | ||
function fieldConditionSingleDependencyToJsonSchema(condition, fieldKey) { | ||
let jsonCondition = undefined; | ||
const innerCondition = condition; | ||
const dependentFieldKey = innerCondition.fieldKey; | ||
if (dependentFieldKey.split('.').length > 1) { | ||
const [parentKey, childKey] = dependentFieldKey.split('.'); | ||
if (innerCondition.operator === 'is') { | ||
jsonCondition = objectConditionToJSONSchema(parentKey, childKey, fieldKey, innerCondition.value, 'is'); | ||
} | ||
else if (innerCondition.operator === 'is_not') { | ||
jsonCondition = objectConditionToJSONSchema(parentKey, childKey, fieldKey, innerCondition.value, 'is_not'); | ||
} | ||
else { | ||
throw new Error(`Unsupported conditionally required field operator: ${innerCondition.operator}`); | ||
} | ||
return jsonCondition; | ||
} | ||
if (innerCondition.operator === 'is') { | ||
if (innerCondition.value === undefined) { | ||
return undefinedConditionValueToJSONSchema(innerCondition.fieldKey, fieldKey, 'is'); | ||
} | ||
jsonCondition = simpleConditionToJSONSchema(innerCondition.fieldKey, fieldKey, innerCondition.value, 'is'); | ||
} | ||
else if (innerCondition.operator === 'is_not') { | ||
if (innerCondition.value === undefined) { | ||
return undefinedConditionValueToJSONSchema(innerCondition.fieldKey, fieldKey, 'is_not'); | ||
} | ||
jsonCondition = simpleConditionToJSONSchema(innerCondition.fieldKey, fieldKey, innerCondition.value, 'is_not'); | ||
} | ||
else { | ||
throw new Error(`Unsupported conditionally required field operator: ${innerCondition.operator}`); | ||
} | ||
return jsonCondition; | ||
} | ||
exports.fieldConditionSingleDependencyToJsonSchema = fieldConditionSingleDependencyToJsonSchema; | ||
function singleFieldConditionsToJsonSchema(fieldKey, singleFieldConditions) { | ||
let jsonCondition = undefined; | ||
if (singleFieldConditions.conditions.length === 1) { | ||
return fieldConditionSingleDependencyToJsonSchema(singleFieldConditions.conditions[0], fieldKey); | ||
} | ||
const innerConditionArray = []; | ||
singleFieldConditions.conditions.forEach((innerCondition) => { | ||
const dependentFieldKey = innerCondition.fieldKey; | ||
if (dependentFieldKey.split('.').length > 1) { | ||
const [parentKey, childKey] = dependentFieldKey.split('.'); | ||
const conditionToJSON = objectConditionToJSONSchema(parentKey, childKey, fieldKey, innerCondition.value, innerCondition.operator, true); | ||
innerConditionArray.push(conditionToJSON); | ||
const innerIfStatement = singleFieldConditions.match === 'any' ? { anyOf: innerConditionArray } : { allOf: innerConditionArray }; | ||
jsonCondition = { if: innerIfStatement, then: generateThenStatement(fieldKey) }; | ||
return jsonCondition; | ||
} | ||
if (innerCondition.value === undefined) { | ||
innerConditionArray.push(undefinedConditionValueToJSONSchema(innerCondition.fieldKey, fieldKey, innerCondition.operator, true)); | ||
} | ||
else { | ||
const conditionToJSON = simpleConditionToJSONSchema(dependentFieldKey, fieldKey, innerCondition.value, innerCondition.operator, true); | ||
innerConditionArray.push(conditionToJSON); | ||
} | ||
}); | ||
const innerIfStatement = singleFieldConditions.match === 'any' ? { anyOf: innerConditionArray } : { allOf: innerConditionArray }; | ||
jsonCondition = { if: innerIfStatement, then: { required: [fieldKey] } }; | ||
return jsonCondition; | ||
} | ||
exports.singleFieldConditionsToJsonSchema = singleFieldConditionsToJsonSchema; | ||
function conditionsToJsonSchema(allFieldConditions) { | ||
const additionalSchema = []; | ||
for (const [fieldKey, singleFieldCondition] of Object.entries(allFieldConditions)) { | ||
const jsonCondition = singleFieldConditionsToJsonSchema(fieldKey, singleFieldCondition); | ||
if (jsonCondition === undefined) { | ||
throw new Error(`Unsupported conditionally required field condition: ${singleFieldCondition}`); | ||
} | ||
if (jsonCondition) { | ||
additionalSchema.push(jsonCondition); | ||
} | ||
} | ||
if (additionalSchema.length === 0) { | ||
return {}; | ||
} | ||
return { allOf: additionalSchema }; | ||
} | ||
exports.conditionsToJsonSchema = conditionsToJsonSchema; | ||
function fieldsToJsonSchema(fields = {}, options, additionalSchema) { | ||
const required = []; | ||
const properties = {}; | ||
const conditions = {}; | ||
for (const [key, field] of Object.entries(fields)) { | ||
@@ -77,5 +234,7 @@ const schemaType = toJsonSchemaType(field.type); | ||
if (schemaType === 'object' && field.properties) { | ||
const propertiesContainsConditionallyRequired = Object.values(field.properties).some((field) => field.required && typeof field.required === 'object'); | ||
if (isMulti) { | ||
schema.items = fieldsToJsonSchema(field.properties, { | ||
additionalProperties: field?.additionalProperties || false | ||
additionalProperties: field?.additionalProperties || false, | ||
omitRequiredSchemas: propertiesContainsConditionallyRequired | ||
}); | ||
@@ -86,11 +245,44 @@ } | ||
...schema, | ||
...fieldsToJsonSchema(field.properties, { additionalProperties: field?.additionalProperties || false }) | ||
...fieldsToJsonSchema(field.properties, { | ||
additionalProperties: field?.additionalProperties || false, | ||
omitRequiredSchemas: propertiesContainsConditionallyRequired | ||
}) | ||
}; | ||
} | ||
for (const [propertyKey, objectField] of Object.entries(field.properties)) { | ||
if (objectField.required === true) { | ||
continue; | ||
} | ||
else if (objectField.required && typeof objectField.required === 'object') { | ||
const dotNotationKey = `${key}.${propertyKey}`; | ||
conditions[dotNotationKey] = objectField.required; | ||
} | ||
} | ||
} | ||
properties[key] = schema; | ||
if (field.required) { | ||
if (field.required === true) { | ||
required.push(key); | ||
} | ||
else if (field.required && typeof field.required === 'object') { | ||
conditions[key] = field.required; | ||
} | ||
} | ||
if (options?.tsType === true) { | ||
return { | ||
$schema: 'http://json-schema.org/schema#', | ||
type: 'object', | ||
additionalProperties: options?.additionalProperties || false, | ||
properties, | ||
required | ||
}; | ||
} | ||
if (options?.omitRequiredSchemas === true) { | ||
return { | ||
$schema: 'http://json-schema.org/schema#', | ||
type: 'object', | ||
additionalProperties: options?.additionalProperties || false, | ||
properties, | ||
...additionalSchema | ||
}; | ||
} | ||
return { | ||
@@ -101,3 +293,5 @@ $schema: 'http://json-schema.org/schema#', | ||
properties, | ||
required | ||
required, | ||
...conditionsToJsonSchema(conditions), | ||
...additionalSchema | ||
}; | ||
@@ -104,0 +298,0 @@ } |
@@ -37,6 +37,6 @@ import { EventEmitterSlug } from '@segment/action-emitters'; | ||
} | ||
export type AudienceResult = { | ||
export declare type AudienceResult = { | ||
externalId: string; | ||
}; | ||
export type AudienceMode = { | ||
export declare type AudienceMode = { | ||
type: 'realtime'; | ||
@@ -47,3 +47,3 @@ } | { | ||
}; | ||
export type Personas = { | ||
export declare type Personas = { | ||
computation_id: string; | ||
@@ -54,3 +54,3 @@ computation_key: string; | ||
}; | ||
export type CreateAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
export declare type CreateAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
settings: Settings; | ||
@@ -63,3 +63,3 @@ audienceSettings?: AudienceSettings; | ||
}; | ||
export type GetAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
export declare type GetAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
settings: Settings; | ||
@@ -97,3 +97,3 @@ audienceSettings?: AudienceSettings; | ||
} | ||
export type Preset = AutomaticPreset | SpecificEventPreset; | ||
export declare type Preset = AutomaticPreset | SpecificEventPreset; | ||
export interface Subscription { | ||
@@ -144,4 +144,4 @@ name?: string; | ||
} | ||
export type AuthenticationScheme<Settings = any> = BasicAuthentication<Settings> | CustomAuthentication<Settings> | OAuth2Authentication<Settings> | OAuthManagedAuthentication<Settings>; | ||
export type SubscriptionMetadata = { | ||
export declare type AuthenticationScheme<Settings = any> = BasicAuthentication<Settings> | CustomAuthentication<Settings> | OAuth2Authentication<Settings> | OAuthManagedAuthentication<Settings>; | ||
export declare type SubscriptionMetadata = { | ||
actionConfigId?: string; | ||
@@ -148,0 +148,0 @@ destinationConfigId?: string; |
@@ -33,3 +33,3 @@ "use strict"; | ||
if (this.authentication?.fields) { | ||
this.settingsSchema = (0, fields_to_jsonschema_1.fieldsToJsonSchema)(this.authentication.fields); | ||
this.settingsSchema = fields_to_jsonschema_1.fieldsToJsonSchema(this.authentication.fields); | ||
} | ||
@@ -43,3 +43,3 @@ for (const action of Object.keys(destination.actions)) { | ||
try { | ||
(0, schema_validation_1.validateSchema)(settings, this.settingsSchema, { | ||
schema_validation_1.validateSchema(settings, this.settingsSchema, { | ||
schemaKey: `${this.name}:settings`, | ||
@@ -65,3 +65,3 @@ exempt: ['dynamicAuthSettings'] | ||
if (createAudienceInput.audienceSettings && Object.keys(createAudienceInput.audienceSettings).length > 0) { | ||
(0, schema_validation_1.validateSchema)(createAudienceInput.audienceSettings, (0, fields_to_jsonschema_1.fieldsToJsonSchema)(audienceFields), { | ||
schema_validation_1.validateSchema(createAudienceInput.audienceSettings, fields_to_jsonschema_1.fieldsToJsonSchema(audienceFields), { | ||
exempt: ['dynamicAuthSettings'] | ||
@@ -72,3 +72,3 @@ }); | ||
const run = async () => { | ||
const auth = (0, parse_settings_1.getAuthData)(settings); | ||
const auth = parse_settings_1.getAuthData(settings); | ||
const context = { | ||
@@ -81,3 +81,3 @@ audienceSettings: createAudienceInput.audienceSettings, | ||
const opts = this.extendRequest?.(context) ?? {}; | ||
const requestClient = (0, create_request_client_1.default)({ ...opts, statsContext: context.statsContext }); | ||
const requestClient = create_request_client_1.default({ ...opts, statsContext: context.statsContext }); | ||
return await audienceConfig?.createAudience(requestClient, createAudienceInput); | ||
@@ -88,3 +88,3 @@ }; | ||
}; | ||
return await (0, retry_1.retry)(run, { retries: 2, onFailedAttempt }); | ||
return await retry_1.retry(run, { retries: 2, onFailedAttempt }); | ||
} | ||
@@ -99,3 +99,3 @@ async getAudience(getAudienceInput) { | ||
const run = async () => { | ||
const auth = (0, parse_settings_1.getAuthData)(settings); | ||
const auth = parse_settings_1.getAuthData(settings); | ||
const context = { | ||
@@ -108,3 +108,3 @@ audienceSettings: getAudienceInput.audienceSettings, | ||
const opts = this.extendRequest?.(context) ?? {}; | ||
const requestClient = (0, create_request_client_1.default)({ ...opts, statsContext: context.statsContext }); | ||
const requestClient = create_request_client_1.default({ ...opts, statsContext: context.statsContext }); | ||
return await audienceConfig?.getAudience(requestClient, getAudienceInput); | ||
@@ -115,7 +115,7 @@ }; | ||
}; | ||
return await (0, retry_1.retry)(run, { retries: 2, onFailedAttempt }); | ||
return await retry_1.retry(run, { retries: 2, onFailedAttempt }); | ||
} | ||
async testAuthentication(settings) { | ||
const destinationSettings = this.getDestinationSettings(settings); | ||
const auth = (0, parse_settings_1.getAuthData)(settings); | ||
const auth = parse_settings_1.getAuthData(settings); | ||
const data = { settings: destinationSettings, auth }; | ||
@@ -132,3 +132,3 @@ const context = { | ||
const options = this.extendRequest?.(context) ?? {}; | ||
const requestClient = (0, create_request_client_1.default)({ ...options, statsContext: context.statsContext }); | ||
const requestClient = create_request_client_1.default({ ...options, statsContext: context.statsContext }); | ||
try { | ||
@@ -150,6 +150,6 @@ await this.authentication.testAuthentication(requestClient, data); | ||
payload: undefined, | ||
auth: (0, parse_settings_1.getAuthData)(settings) | ||
auth: parse_settings_1.getAuthData(settings) | ||
}; | ||
const options = this.extendRequest?.(context) ?? {}; | ||
const requestClient = (0, create_request_client_1.default)({ ...options, statsContext: context.statsContext }); | ||
const requestClient = create_request_client_1.default({ ...options, statsContext: context.statsContext }); | ||
if (!this.authentication?.refreshAccessToken) { | ||
@@ -228,3 +228,3 @@ return undefined; | ||
const isBatch = Array.isArray(events); | ||
const subscriptionStartedAt = (0, time_1.time)(); | ||
const subscriptionStartedAt = time_1.time(); | ||
const actionSlug = subscription.partnerAction; | ||
@@ -267,3 +267,3 @@ const input = { | ||
} | ||
const parsedSubscription = (0, destination_subscriptions_1.parseFql)(subscription.subscribe); | ||
const parsedSubscription = destination_subscriptions_1.parseFql(subscription.subscribe); | ||
if (parsedSubscription.error) { | ||
@@ -292,3 +292,3 @@ const response = { | ||
const event = allEvents[i]; | ||
if (!(0, destination_subscriptions_1.validate)(parsedSubscription, event)) { | ||
if (!destination_subscriptions_1.validate(parsedSubscription, event)) { | ||
multistatus[i] = { | ||
@@ -334,4 +334,4 @@ status: 400, | ||
finally { | ||
const subscriptionEndedAt = (0, time_1.time)(); | ||
const subscriptionDuration = (0, time_1.duration)(subscriptionStartedAt, subscriptionEndedAt); | ||
const subscriptionEndedAt = time_1.time(); | ||
const subscriptionDuration = time_1.duration(subscriptionStartedAt, subscriptionEndedAt); | ||
options?.onComplete?.({ | ||
@@ -363,3 +363,3 @@ duration: subscriptionDuration, | ||
const run = async () => { | ||
const auth = (0, parse_settings_1.getAuthData)(settings); | ||
const auth = parse_settings_1.getAuthData(settings); | ||
const data = { | ||
@@ -376,3 +376,3 @@ payload, | ||
const opts = this.extendRequest?.(context) ?? {}; | ||
const requestClient = (0, create_request_client_1.default)({ ...opts, statsContext: context.statsContext }); | ||
const requestClient = create_request_client_1.default({ ...opts, statsContext: context.statsContext }); | ||
const deleteResult = await this.definition.onDelete?.(requestClient, data); | ||
@@ -385,3 +385,3 @@ const result = deleteResult ?? { output: 'no onDelete defined' }; | ||
}; | ||
return await (0, retry_1.retry)(run, { retries: 2, onFailedAttempt }); | ||
return await retry_1.retry(run, { retries: 2, onFailedAttempt }); | ||
} | ||
@@ -393,3 +393,3 @@ async onSubscriptions(data, settings, options) { | ||
const run = async () => { | ||
const authData = (0, parse_settings_1.getAuthData)(settings); | ||
const authData = parse_settings_1.getAuthData(settings); | ||
const promises = subscriptions.map((subscription) => this.onSubscription(subscription, data, destinationSettings, authData, options)); | ||
@@ -415,3 +415,3 @@ const results = await Promise.all(promises); | ||
}; | ||
return await (0, retry_1.retry)(run, { retries: MAX_ATTEMPTS, onFailedAttempt, shouldRetry }); | ||
return await retry_1.retry(run, { retries: MAX_ATTEMPTS, onFailedAttempt, shouldRetry }); | ||
} | ||
@@ -448,3 +448,3 @@ getSubscriptions(settings) { | ||
await options?.onTokenRefresh?.(newTokens); | ||
settings = (0, parse_settings_1.updateOAuthSettings)(settings, newTokens); | ||
settings = parse_settings_1.updateOAuthSettings(settings, newTokens); | ||
return settings; | ||
@@ -454,3 +454,3 @@ } | ||
const destinationSettings = this.getDestinationSettings(settings); | ||
const oauthSettings = (0, parse_settings_1.getOAuth2Data)(settings); | ||
const oauthSettings = parse_settings_1.getOAuth2Data(settings); | ||
const newTokens = await this.refreshAccessToken(destinationSettings, oauthSettings, options?.synchronizeRefreshAccessToken); | ||
@@ -457,0 +457,0 @@ if (!newTokens) { |
@@ -9,4 +9,4 @@ import { StateContext, Logger, StatsContext, TransactionContext, EngageDestinationCache, ActionHookType, SubscriptionMetadata, RequestFn } from './index'; | ||
import type { ErrorCodes, MultiStatusErrorReporter } from '../errors'; | ||
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | ||
export type MaybePromise<T> = T | Promise<T>; | ||
export declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | ||
export declare type MaybePromise<T> = T | Promise<T>; | ||
export interface Result { | ||
@@ -66,6 +66,6 @@ output?: JSONObject | string | null | undefined; | ||
} | ||
export type FieldTypeName = 'string' | 'text' | 'number' | 'integer' | 'datetime' | 'boolean' | 'password' | 'object'; | ||
type FieldCategory = 'identifier' | 'data' | 'internal' | 'config' | 'sync'; | ||
type FieldInputMethods = 'literal' | 'variable' | 'function' | 'enrichment' | 'freeform'; | ||
type FieldDisplayMode = 'expanded' | 'normal' | 'collapsed'; | ||
export declare type FieldTypeName = 'string' | 'text' | 'number' | 'integer' | 'datetime' | 'boolean' | 'password' | 'object'; | ||
declare type FieldCategory = 'identifier' | 'data' | 'internal' | 'config' | 'sync'; | ||
declare type FieldInputMethods = 'literal' | 'variable' | 'function' | 'enrichment' | 'freeform'; | ||
declare type FieldDisplayMode = 'expanded' | 'normal' | 'collapsed'; | ||
export interface InputFieldJSONSchema { | ||
@@ -83,3 +83,3 @@ label: string; | ||
}>; | ||
required?: boolean; | ||
required?: boolean | DependsOnConditions; | ||
properties?: Record<string, Optional<InputField, 'description'>>; | ||
@@ -113,3 +113,3 @@ format?: 'date' | 'time' | 'date-time' | 'uri' | 'uri-reference' | 'uri-template' | 'email' | 'hostname' | 'ipv4' | 'ipv6' | 'regex' | 'uuid' | 'password' | 'text'; | ||
} | ||
export type Condition = FieldCondition | SyncModeCondition; | ||
export declare type Condition = FieldCondition | SyncModeCondition; | ||
export interface DependsOnConditions { | ||
@@ -119,3 +119,3 @@ match?: 'any' | 'all'; | ||
} | ||
export type FieldValue = string | number | boolean | object | Directive; | ||
export declare type FieldValue = string | number | boolean | object | Directive; | ||
export interface IfDirective { | ||
@@ -140,4 +140,4 @@ '@if': { | ||
} | ||
export type Directive = IfDirective | TemplateDirective | PathDirective | CaseDirective; | ||
export type RequestExtension<Settings, Payload = undefined> = (data: ExecuteInput<Settings, Payload>) => RequestOptions; | ||
export declare type Directive = IfDirective | TemplateDirective | PathDirective | CaseDirective; | ||
export declare type RequestExtension<Settings, Payload = undefined> = (data: ExecuteInput<Settings, Payload>) => RequestOptions; | ||
export interface DeletionPayload { | ||
@@ -147,5 +147,5 @@ userId: ID; | ||
} | ||
export type Deletion<Settings, Return = any> = (request: RequestClient, data: ExecuteInput<Settings, DeletionPayload>) => MaybePromise<Return>; | ||
export declare type Deletion<Settings, Return = any> = (request: RequestClient, data: ExecuteInput<Settings, DeletionPayload>) => MaybePromise<Return>; | ||
export declare const syncModeTypes: readonly ["add", "update", "upsert", "delete", "mirror"]; | ||
export type SyncMode = typeof syncModeTypes[number]; | ||
export declare type SyncMode = typeof syncModeTypes[number]; | ||
export interface SyncModeOption { | ||
@@ -161,3 +161,3 @@ label: string; | ||
} | ||
export type ActionDestinationSuccessResponseType = { | ||
export declare type ActionDestinationSuccessResponseType = { | ||
status: number; | ||
@@ -167,3 +167,3 @@ sent: JSONLikeObject | string; | ||
}; | ||
export type ActionDestinationErrorResponseType = { | ||
export declare type ActionDestinationErrorResponseType = { | ||
status: number; | ||
@@ -175,5 +175,5 @@ errortype?: keyof typeof ErrorCodes; | ||
}; | ||
export type ResultMultiStatusNode = ActionDestinationSuccessResponseType | (ActionDestinationErrorResponseType & { | ||
export declare type ResultMultiStatusNode = ActionDestinationSuccessResponseType | (ActionDestinationErrorResponseType & { | ||
errorreporter: MultiStatusErrorReporter; | ||
}); | ||
export {}; |
@@ -8,3 +8,3 @@ import { CustomError } from 'ts-custom-error'; | ||
} | ||
type RetryableStatusCodes = 408 | 423 | 429 | 500 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 598 | 599; | ||
declare type RetryableStatusCodes = 408 | 423 | 429 | 500 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 598 | 599; | ||
export declare class RetryableError extends CustomError { | ||
@@ -11,0 +11,0 @@ status: RetryableStatusCodes; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,11 +0,11 @@ | ||
export type JSONPrimitive = string | number | boolean | null; | ||
export type JSONValue = JSONPrimitive | JSONObject | JSONArray; | ||
export type JSONObject = { | ||
export declare type JSONPrimitive = string | number | boolean | null; | ||
export declare type JSONValue = JSONPrimitive | JSONObject | JSONArray; | ||
export declare type JSONObject = { | ||
[member: string]: JSONValue; | ||
}; | ||
export type JSONArray = Array<JSONValue>; | ||
export type JSONLike = JSONPrimitive | JSONLikeObject | Array<JSONLike> | Date | undefined; | ||
export type JSONLikeObject = { | ||
export declare type JSONArray = Array<JSONValue>; | ||
export declare type JSONLike = JSONPrimitive | JSONLikeObject | Array<JSONLike> | Date | undefined; | ||
export declare type JSONLikeObject = { | ||
[member: string]: JSONLike; | ||
[member: number]: JSONLike; | ||
}; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const flattenObject = (input, prefix = '', separator = '.', ignoreArrays = false) => { | ||
if ((0, real_type_of_1.isObject)(input) || (!ignoreArrays && (0, real_type_of_1.isArray)(input))) { | ||
if (real_type_of_1.isObject(input) || (!ignoreArrays && real_type_of_1.isArray(input))) { | ||
return Object.entries(input).reduce((acc, [key, value]) => { | ||
@@ -12,3 +12,3 @@ const newKey = prefix ? `${prefix}${separator}${key}` : key; | ||
...acc, | ||
...(0, exports.flattenObject)(value, newKey, separator, ignoreArrays) | ||
...exports.flattenObject(value, newKey, separator, ignoreArrays) | ||
}; | ||
@@ -15,0 +15,0 @@ }, {}); |
import { JSONObject, JSONLikeObject } from '../json-object'; | ||
export type InputData = { | ||
export declare type InputData = { | ||
[key: string]: unknown; | ||
}; | ||
export type Features = { | ||
export declare type Features = { | ||
[key: string]: boolean; | ||
@@ -7,0 +7,0 @@ }; |
@@ -28,3 +28,3 @@ "use strict"; | ||
if (typeof str !== 'string') { | ||
throw new Error(`${name}: expected string, got ${(0, real_type_of_1.realTypeOf)(str)}`); | ||
throw new Error(`${name}: expected string, got ${real_type_of_1.realTypeOf(str)}`); | ||
} | ||
@@ -39,3 +39,3 @@ return fn(str, payload); | ||
if (typeof directiveFn !== 'function') { | ||
throw new Error(`${name} is not a valid directive, got ${(0, real_type_of_1.realTypeOf)(directiveFn)}`); | ||
throw new Error(`${name} is not a valid directive, got ${real_type_of_1.realTypeOf(directiveFn)}`); | ||
} | ||
@@ -46,3 +46,3 @@ return directiveFn(value, payload); | ||
let condition = false; | ||
if (!(0, real_type_of_1.isObject)(opts)) { | ||
if (!real_type_of_1.isObject(opts)) { | ||
throw new Error('@if requires an object with an "exists" key'); | ||
@@ -69,3 +69,3 @@ } | ||
registerDirective('@case', (opts, payload) => { | ||
if (!(0, real_type_of_1.isObject)(opts)) { | ||
if (!real_type_of_1.isObject(opts)) { | ||
throw new Error('@case requires an object with a "operator" key'); | ||
@@ -105,3 +105,3 @@ } | ||
registerDirective('@replace', (opts, payload) => { | ||
if (!(0, real_type_of_1.isObject)(opts)) { | ||
if (!real_type_of_1.isObject(opts)) { | ||
throw new Error('@replace requires an object with a "pattern" key'); | ||
@@ -156,10 +156,10 @@ } | ||
if (!Array.isArray(data)) { | ||
throw new Error(`@arrayPath expected array, got ${(0, real_type_of_1.realTypeOf)(data)}`); | ||
throw new Error(`@arrayPath expected array, got ${real_type_of_1.realTypeOf(data)}`); | ||
} | ||
const [path, itemShape] = data; | ||
const root = typeof path === 'string' ? (0, get_1.get)(payload, path.replace('$.', '')) : resolve(path, payload); | ||
if (['object', 'array'].includes((0, real_type_of_1.realTypeOf)(root)) && | ||
(0, real_type_of_1.realTypeOf)(itemShape) === 'object' && | ||
const root = typeof path === 'string' ? get_1.get(payload, path.replace('$.', '')) : resolve(path, payload); | ||
if (['object', 'array'].includes(real_type_of_1.realTypeOf(root)) && | ||
real_type_of_1.realTypeOf(itemShape) === 'object' && | ||
Object.keys(itemShape).length > 0) { | ||
return (0, arrify_1.arrify)(root).map((item) => resolve(itemShape, item)); | ||
return arrify_1.arrify(root).map((item) => resolve(itemShape, item)); | ||
} | ||
@@ -169,6 +169,6 @@ return root; | ||
registerStringDirective('@path', (path, payload) => { | ||
return (0, get_1.get)(payload, path.replace('$.', '')); | ||
return get_1.get(payload, path.replace('$.', '')); | ||
}); | ||
registerStringDirective('@template', (template, payload) => { | ||
return (0, placeholders_1.render)(template, payload); | ||
return placeholders_1.render(template, payload); | ||
}); | ||
@@ -179,3 +179,3 @@ registerDirective('@literal', (value, payload) => { | ||
registerDirective('@flatten', (opts, payload) => { | ||
if (!(0, real_type_of_1.isObject)(opts)) { | ||
if (!real_type_of_1.isObject(opts)) { | ||
throw new Error('@flatten requires an object with a "separator" key'); | ||
@@ -191,6 +191,6 @@ } | ||
const value = resolve(opts.value, payload); | ||
return (0, flatten_1.flattenObject)(value, '', separator, Boolean(opts.omitArrays)); | ||
return flatten_1.flattenObject(value, '', separator, Boolean(opts.omitArrays)); | ||
}); | ||
registerDirective('@json', (opts, payload) => { | ||
if (!(0, real_type_of_1.isObject)(opts)) { | ||
if (!real_type_of_1.isObject(opts)) { | ||
throw new Error('@json requires an object with a "value" key'); | ||
@@ -216,3 +216,3 @@ } | ||
registerDirective('@merge', (opts, payload) => { | ||
if (!(0, real_type_of_1.isObject)(opts)) { | ||
if (!real_type_of_1.isObject(opts)) { | ||
throw new Error('@merge requires an object with an "objects" key and a "direction" key'); | ||
@@ -236,3 +236,3 @@ } | ||
registerDirective('@transform', (opts, payload) => { | ||
if (!(0, real_type_of_1.isObject)(opts)) { | ||
if (!real_type_of_1.isObject(opts)) { | ||
throw new Error('@transform requires an object with an "apply" key and a "mapping" key'); | ||
@@ -246,3 +246,3 @@ } | ||
} | ||
if (!(0, real_type_of_1.isObject)(opts.apply)) { | ||
if (!real_type_of_1.isObject(opts.apply)) { | ||
throw new Error('@transform "apply" key should be an object'); | ||
@@ -261,3 +261,3 @@ } | ||
function cleanNulls(value) { | ||
if ((0, real_type_of_1.isObject)(value)) { | ||
if (real_type_of_1.isObject(value)) { | ||
const cleaned = Object.assign({}, value); | ||
@@ -269,3 +269,3 @@ for (const key of Object.keys(value)) { | ||
} | ||
else if ((0, real_type_of_1.isObject)(val)) { | ||
else if (real_type_of_1.isObject(val)) { | ||
cleaned[key] = cleanNulls(val); | ||
@@ -300,6 +300,6 @@ } | ||
function resolve(mapping, payload) { | ||
if (!(0, real_type_of_1.isObject)(mapping) && !(0, real_type_of_1.isArray)(mapping)) { | ||
if (!real_type_of_1.isObject(mapping) && !real_type_of_1.isArray(mapping)) { | ||
return mapping; | ||
} | ||
if ((0, is_directive_1.isDirective)(mapping)) { | ||
if (is_directive_1.isDirective(mapping)) { | ||
return runDirective(mapping, payload); | ||
@@ -317,3 +317,3 @@ } | ||
function transform(mapping, data = {}) { | ||
const realType = (0, real_type_of_1.realTypeOf)(data); | ||
const realType = real_type_of_1.realTypeOf(data); | ||
if (realType !== 'object') { | ||
@@ -323,5 +323,5 @@ throw new Error(`data must be an object, got ${realType}`); | ||
const mappingToProcess = getMappingToProcess(mapping); | ||
(0, validate_1.default)(mappingToProcess); | ||
validate_1.default(mappingToProcess); | ||
const resolved = resolve(mappingToProcess, data); | ||
const cleaned = (0, remove_undefined_1.removeUndefined)(resolved); | ||
const cleaned = remove_undefined_1.removeUndefined(resolved); | ||
return cleaned; | ||
@@ -331,12 +331,12 @@ } | ||
function transformBatch(mapping, data = []) { | ||
const realType = (0, real_type_of_1.realTypeOf)(data); | ||
if (!(0, real_type_of_1.isArray)(data)) { | ||
const realType = real_type_of_1.realTypeOf(data); | ||
if (!real_type_of_1.isArray(data)) { | ||
throw new Error(`data must be an array, got ${realType}`); | ||
} | ||
const mappingToProcess = getMappingToProcess(mapping); | ||
(0, validate_1.default)(mappingToProcess); | ||
validate_1.default(mappingToProcess); | ||
const resolved = data.map((d) => resolve(mappingToProcess, d)); | ||
return (0, remove_undefined_1.removeUndefined)(resolved); | ||
return remove_undefined_1.removeUndefined(resolved); | ||
} | ||
exports.transformBatch = transformBatch; | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
function isDirective(obj) { | ||
if (!(0, real_type_of_1.isObject)(obj)) { | ||
if (!real_type_of_1.isObject(obj)) { | ||
return false; | ||
@@ -9,0 +9,0 @@ } |
@@ -8,3 +8,3 @@ "use strict"; | ||
if (typeof template !== 'string') { | ||
throw new TypeError(`Invalid template! Template should be a "string" but ${(0, real_type_of_1.realTypeOf)(template)} was given.`); | ||
throw new TypeError(`Invalid template! Template should be a "string" but ${real_type_of_1.realTypeOf(template)} was given.`); | ||
} | ||
@@ -14,3 +14,3 @@ function replacer(chars) { | ||
match = match.slice(chars, -chars).trim(); | ||
const value = (0, get_1.get)(data, match); | ||
const value = get_1.get(data, match); | ||
return (value ?? ''); | ||
@@ -17,0 +17,0 @@ }; |
@@ -29,3 +29,3 @@ "use strict"; | ||
function realTypeOrDirective(value) { | ||
const type = (0, real_type_of_1.realTypeOf)(value); | ||
const type = real_type_of_1.realTypeOf(value); | ||
if (type === 'object' && Object.keys(value).some((k) => k.startsWith('@'))) { | ||
@@ -38,4 +38,4 @@ return 'directive'; | ||
function validateDirective(obj, stack = []) { | ||
if (!(0, is_directive_1.isDirective)(obj) && !(0, real_type_of_1.isObject)(obj)) { | ||
const type = (0, real_type_of_1.realTypeOf)(obj); | ||
if (!is_directive_1.isDirective(obj) && !real_type_of_1.isObject(obj)) { | ||
const type = real_type_of_1.realTypeOf(obj); | ||
throw new ValidationError(`should be a directive object but it is ${indefiniteArticle(type)} ${type}`, stack); | ||
@@ -189,3 +189,3 @@ } | ||
function validateArray(arr, stack = []) { | ||
const type = (0, real_type_of_1.realTypeOf)(arr); | ||
const type = real_type_of_1.realTypeOf(arr); | ||
if (type !== 'array') { | ||
@@ -192,0 +192,0 @@ throw new ValidationError(`should be an array but it is ${indefiniteArticle(type)} ${type}`, stack); |
@@ -1,2 +0,2 @@ | ||
type ValueType = 'enrichment' | 'function' | 'literal' | 'variable'; | ||
declare type ValueType = 'enrichment' | 'function' | 'literal' | 'variable'; | ||
export interface DirectiveMetadata { | ||
@@ -22,3 +22,3 @@ _metadata?: { | ||
export declare function isPathDirective(value: FieldValue): value is PathDirective; | ||
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = { | ||
declare type RequireOnlyOne<T, Keys extends keyof T = keyof T> = { | ||
[K in Keys]-?: Partial<Record<Exclude<Keys, K>, undefined>> & Required<Pick<T, K>>; | ||
@@ -94,5 +94,5 @@ }[Keys] & Pick<T, Exclude<keyof T, Keys>>; | ||
export declare function isExcludeWhenNullDirective(value: FieldValue): value is ExcludeWhenNullDirective; | ||
export type Directive = ArrayPathDirective | CaseDirective | IfDirective | LiteralDirective | PathDirective | ReplaceDirective | TemplateDirective | JSONDirective | FlattenDirective | MergeDirective | TransformDirective | ExcludeWhenNullDirective; | ||
export type PrimitiveValue = boolean | number | string | null; | ||
export type FieldValue = Directive | PrimitiveValue | { | ||
export declare type Directive = ArrayPathDirective | CaseDirective | IfDirective | LiteralDirective | PathDirective | ReplaceDirective | TemplateDirective | JSONDirective | FlattenDirective | MergeDirective | TransformDirective | ExcludeWhenNullDirective; | ||
export declare type PrimitiveValue = boolean | number | string | null; | ||
export declare type FieldValue = Directive | PrimitiveValue | { | ||
[key: string]: FieldValue; | ||
@@ -99,0 +99,0 @@ } | FieldValue[] | undefined; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const password = options.password || ''; | ||
const encoded = (0, btoa_lite_1.default)(`${username}:${password}`); | ||
const encoded = btoa_lite_1.default(`${username}:${password}`); | ||
const authorization = `Basic ${encoded}`; | ||
@@ -14,0 +14,0 @@ return { |
@@ -10,3 +10,3 @@ "use strict"; | ||
} | ||
if ((0, real_type_of_1.isArray)(obj)) { | ||
if (real_type_of_1.isArray(obj)) { | ||
if (!schema.items) | ||
@@ -16,3 +16,3 @@ return obj; | ||
} | ||
if ((0, real_type_of_1.isObject)(obj)) { | ||
if (real_type_of_1.isObject(obj)) { | ||
if (!schema.properties) | ||
@@ -32,3 +32,3 @@ return obj; | ||
} | ||
const schemaType = (0, arrify_1.arrify)(schema.type); | ||
const schemaType = arrify_1.arrify(schema.type); | ||
if (obj === null && !schemaType.includes('null')) { | ||
@@ -35,0 +35,0 @@ return undefined; |
@@ -9,3 +9,3 @@ "use strict"; | ||
} | ||
else if ((0, real_type_of_1.isObject)(value)) { | ||
else if (real_type_of_1.isObject(value)) { | ||
const cleaned = Object.assign({}, value); | ||
@@ -12,0 +12,0 @@ Object.keys(cleaned).forEach((key) => { |
@@ -27,5 +27,5 @@ /// <reference types="node" /> | ||
} | ||
type MaybePromise<T> = Promise<T> | T; | ||
export type BeforeRequestHook = (options: NormalizedOptions) => MaybePromise<RequestOptions | void>; | ||
export type AfterResponseHook<OutputResponse extends Response = Response> = (request: Request, options: NormalizedOptions, response: Response) => MaybePromise<OutputResponse | void>; | ||
declare type MaybePromise<T> = Promise<T> | T; | ||
export declare type BeforeRequestHook = (options: NormalizedOptions) => MaybePromise<RequestOptions | void>; | ||
export declare type AfterResponseHook<OutputResponse extends Response = Response> = (request: Request, options: NormalizedOptions, response: Response) => MaybePromise<OutputResponse | void>; | ||
export declare class HTTPError extends CustomError { | ||
@@ -32,0 +32,0 @@ request: Request; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -25,4 +21,8 @@ if (k2 === undefined) k2 = k; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TimeoutError = exports.HTTPError = exports.DEFAULT_REQUEST_TIMEOUT = void 0; | ||
const abort_controller_1 = __importDefault(require("abort-controller")); | ||
const ts_custom_error_1 = require("ts-custom-error"); | ||
@@ -84,3 +84,3 @@ const fetch_1 = __importStar(require("./fetch")); | ||
for (const source of sources) { | ||
if (!(0, real_type_of_1.isObject)(source)) { | ||
if (!real_type_of_1.isObject(source)) { | ||
throw new TypeError(`The 'options' argument must be an object`); | ||
@@ -120,3 +120,3 @@ } | ||
}, options.timeout); | ||
void (0, fetch_1.default)(request) | ||
void fetch_1.default(request) | ||
.then(resolve) | ||
@@ -138,3 +138,3 @@ .catch(reject) | ||
}; | ||
this.abortController = new AbortController(); | ||
this.abortController = new abort_controller_1.default(); | ||
if (this.options.signal) { | ||
@@ -175,3 +175,3 @@ this.options.signal.addEventListener('abort', () => { | ||
const newOptions = await hook({ ...this.options }); | ||
if (newOptions && (0, real_type_of_1.isObject)(newOptions)) { | ||
if (newOptions && real_type_of_1.isObject(newOptions)) { | ||
this.setOptions(this.request.url, mergeOptions(this.options, newOptions)); | ||
@@ -181,3 +181,3 @@ } | ||
if (this.options.timeout === false) { | ||
return (0, fetch_1.default)(this.request.clone()); | ||
return fetch_1.default(this.request.clone()); | ||
} | ||
@@ -184,0 +184,0 @@ return timeoutFetch(this.request.clone(), this.abortController, this.options); |
@@ -12,3 +12,3 @@ "use strict"; | ||
const arrify_1 = require("./arrify"); | ||
const ajv = (0, ajv_formats_1.default)(new ajv_1.default({ | ||
const ajv = ajv_formats_1.default(new ajv_1.default({ | ||
coerceTypes: 'array', | ||
@@ -22,6 +22,6 @@ allErrors: true, | ||
ajv.addFormat('date-like', (data) => { | ||
let date = (0, dayjs_1.default)(data); | ||
let date = dayjs_1.default(data); | ||
if (String(Number(data)) === data) { | ||
if (data.length === 13) { | ||
date = (0, dayjs_1.default)(Number(data)); | ||
date = dayjs_1.default(Number(data)); | ||
} | ||
@@ -46,3 +46,3 @@ date = dayjs_1.default.unix(Number(data)); | ||
} | ||
(0, arrify_1.arrifyFields)(obj, schema); | ||
arrify_1.arrifyFields(obj, schema); | ||
const isValid = validate(obj); | ||
@@ -49,0 +49,0 @@ exempt.forEach((prop) => { |
import { JSONValue } from './json-object'; | ||
export type ID = string | null | undefined; | ||
type CompactMetricType = 'g' | 'c'; | ||
export declare type ID = string | null | undefined; | ||
declare type CompactMetricType = 'g' | 'c'; | ||
interface CompactMetric { | ||
@@ -11,7 +11,7 @@ m: string; | ||
} | ||
export type Integrations = { | ||
export declare type Integrations = { | ||
All?: boolean; | ||
[integration: string]: boolean | undefined; | ||
}; | ||
export type Options = { | ||
export declare type Options = { | ||
integrations?: Integrations; | ||
@@ -18,0 +18,0 @@ anonymousId?: ID; |
@@ -6,3 +6,3 @@ import { AllRequestOptions, RequestOptions } from './request-client'; | ||
} | ||
export type RequestClient = ReturnType<typeof createRequestClient>; | ||
export default function createRequestClient(...requestOptions: AllRequestOptions[]): <Data = unknown>(url: string, options?: RequestOptions) => Promise<ModifiedResponse<Data>>; | ||
export declare type RequestClient = ReturnType<typeof createRequestClient>; | ||
export default function createRequestClient(...requestOptions: AllRequestOptions[]): <Data = unknown>(url: string, options?: RequestOptions | undefined) => Promise<ModifiedResponse<Data>>; |
@@ -10,5 +10,5 @@ /// <reference types="node" /> | ||
import { Logger, StatsContext, TransactionContext, StateContext, EngageDestinationCache, SubscriptionMetadata } from './index'; | ||
type MaybePromise<T> = T | Promise<T>; | ||
type RequestClient = ReturnType<typeof createRequestClient>; | ||
export type RequestFn<Settings, Payload, Return = any, AudienceSettings = any, ActionHookInputs = any> = (request: RequestClient, data: ExecuteInput<Settings, Payload, AudienceSettings, ActionHookInputs>) => MaybePromise<Return>; | ||
declare type MaybePromise<T> = T | Promise<T>; | ||
declare type RequestClient = ReturnType<typeof createRequestClient>; | ||
export declare type RequestFn<Settings, Payload, Return = any, AudienceSettings = any, ActionHookInputs = any> = (request: RequestClient, data: ExecuteInput<Settings, Payload, AudienceSettings, ActionHookInputs>) => MaybePromise<Return>; | ||
export interface BaseActionDefinition { | ||
@@ -22,5 +22,5 @@ title: string; | ||
} | ||
type HookValueTypes = string | boolean | number | Array<string | boolean | number>; | ||
type GenericActionHookValues = Record<string, HookValueTypes>; | ||
type GenericActionHookBundle = { | ||
declare type HookValueTypes = string | boolean | number | Array<string | boolean | number>; | ||
declare type GenericActionHookValues = Record<string, HookValueTypes>; | ||
declare type GenericActionHookBundle = { | ||
[K in ActionHookType]?: { | ||
@@ -31,4 +31,4 @@ inputs?: GenericActionHookValues; | ||
}; | ||
type IsArray<T> = T extends (infer U)[] ? U : never; | ||
type PerformBatchResponse = MaybePromise<MultiStatusResponse> | MaybePromise<unknown>; | ||
declare type IsArray<T> = T extends (infer U)[] ? U : never; | ||
declare type PerformBatchResponse = MaybePromise<MultiStatusResponse> | MaybePromise<unknown>; | ||
export interface ActionDefinition<Settings, Payload = any, AudienceSettings = any, GeneratedActionHookBundle extends GenericActionHookBundle = any> extends BaseActionDefinition { | ||
@@ -50,3 +50,3 @@ dynamicFields?: { | ||
export declare const hookTypeStrings: readonly ["onMappingSave", "retlOnMappingSave"]; | ||
export type ActionHookType = typeof hookTypeStrings[number]; | ||
export declare type ActionHookType = typeof hookTypeStrings[number]; | ||
export interface ActionHookResponse<GeneratedActionHookOutputs> { | ||
@@ -53,0 +53,0 @@ successMessage?: string; |
import { JSONSchema4 } from 'json-schema'; | ||
import type { InputField, GlobalSetting, Optional } from './types'; | ||
export type MinimalInputField = Optional<InputField, 'description'> | (Optional<GlobalSetting, 'description'> & { | ||
import type { InputField, GlobalSetting, Optional, DependsOnConditions, Condition } from './types'; | ||
export declare type MinimalInputField = Optional<InputField, 'description'> | (Optional<GlobalSetting, 'description'> & { | ||
additionalProperties?: boolean; | ||
}); | ||
export type MinimalFields = Record<string, MinimalInputField>; | ||
export declare type MinimalFields = Record<string, MinimalInputField>; | ||
interface SchemaOptions { | ||
tsType?: boolean; | ||
additionalProperties?: boolean; | ||
omitRequiredSchemas?: boolean; | ||
} | ||
export declare function fieldsToJsonSchema(fields?: MinimalFields, options?: SchemaOptions): JSONSchema4; | ||
export declare function fieldConditionSingleDependencyToJsonSchema(condition: Condition, fieldKey: string): JSONSchema4; | ||
export declare function singleFieldConditionsToJsonSchema(fieldKey: string, singleFieldConditions: DependsOnConditions): JSONSchema4 | undefined; | ||
export declare function conditionsToJsonSchema(allFieldConditions: Record<string, DependsOnConditions>): JSONSchema4; | ||
export declare function fieldsToJsonSchema(fields?: MinimalFields, options?: SchemaOptions, additionalSchema?: JSONSchema4): JSONSchema4; | ||
export {}; |
@@ -13,5 +13,159 @@ function toJsonSchemaType(type) { | ||
} | ||
export function fieldsToJsonSchema(fields = {}, options) { | ||
const fieldKeyIsDotNotation = (fieldKey) => { | ||
return fieldKey.split('.').length > 1; | ||
}; | ||
const generateThenStatement = (fieldKey) => { | ||
if (fieldKeyIsDotNotation(fieldKey)) { | ||
const [parentKey, childKey] = fieldKey.split('.'); | ||
return { | ||
required: [parentKey], | ||
properties: { | ||
[parentKey]: { | ||
required: [childKey] | ||
} | ||
} | ||
}; | ||
} | ||
return { | ||
required: [fieldKey] | ||
}; | ||
}; | ||
const undefinedConditionValueToJSONSchema = (dependantFieldKey, fieldKey, operator, multiple) => { | ||
if (operator !== 'is' && operator !== 'is_not') { | ||
throw new Error(`Unsupported conditionally required field operator: ${operator}`); | ||
} | ||
const insideIfStatement = operator === 'is' ? { not: { required: [dependantFieldKey] } } : { required: [dependantFieldKey] }; | ||
if (multiple) { | ||
return insideIfStatement; | ||
} | ||
if (operator === 'is') { | ||
const fieldIsNull = { properties: { [dependantFieldKey]: { type: 'null' } } }; | ||
return { | ||
if: { anyOf: [insideIfStatement, fieldIsNull] }, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
} | ||
const fieldIsNotNull = { not: { properties: { [dependantFieldKey]: { type: 'null' } } } }; | ||
return { | ||
if: { allOf: [insideIfStatement, fieldIsNotNull] }, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
}; | ||
const simpleConditionToJSONSchema = (dependantFieldKey, fieldKey, dependantValue, operator, multiple) => { | ||
const dependantValueToJSONSchema = operator === 'is' ? { const: dependantValue } : { not: { const: dependantValue } }; | ||
if (multiple) { | ||
return { | ||
properties: { [dependantFieldKey]: dependantValueToJSONSchema }, | ||
required: [dependantFieldKey] | ||
}; | ||
} | ||
return { | ||
if: { | ||
properties: { [dependantFieldKey]: dependantValueToJSONSchema } | ||
}, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
}; | ||
const objectConditionToJSONSchema = (objectParentKey, objectChildKey, fieldKey, dependantValue, operator, multiple) => { | ||
const dependantValueToJSONSchema = operator === 'is' ? { const: dependantValue } : { not: { const: dependantValue } }; | ||
if (multiple) { | ||
return { | ||
properties: { | ||
[objectParentKey]: { properties: { [objectChildKey]: dependantValueToJSONSchema }, required: [objectChildKey] } | ||
}, | ||
required: [objectParentKey] | ||
}; | ||
} | ||
return { | ||
if: { | ||
properties: { | ||
[objectParentKey]: { properties: { [objectChildKey]: dependantValueToJSONSchema }, required: [objectChildKey] } | ||
}, | ||
required: [objectParentKey] | ||
}, | ||
then: generateThenStatement(fieldKey) | ||
}; | ||
}; | ||
export function fieldConditionSingleDependencyToJsonSchema(condition, fieldKey) { | ||
let jsonCondition = undefined; | ||
const innerCondition = condition; | ||
const dependentFieldKey = innerCondition.fieldKey; | ||
if (dependentFieldKey.split('.').length > 1) { | ||
const [parentKey, childKey] = dependentFieldKey.split('.'); | ||
if (innerCondition.operator === 'is') { | ||
jsonCondition = objectConditionToJSONSchema(parentKey, childKey, fieldKey, innerCondition.value, 'is'); | ||
} | ||
else if (innerCondition.operator === 'is_not') { | ||
jsonCondition = objectConditionToJSONSchema(parentKey, childKey, fieldKey, innerCondition.value, 'is_not'); | ||
} | ||
else { | ||
throw new Error(`Unsupported conditionally required field operator: ${innerCondition.operator}`); | ||
} | ||
return jsonCondition; | ||
} | ||
if (innerCondition.operator === 'is') { | ||
if (innerCondition.value === undefined) { | ||
return undefinedConditionValueToJSONSchema(innerCondition.fieldKey, fieldKey, 'is'); | ||
} | ||
jsonCondition = simpleConditionToJSONSchema(innerCondition.fieldKey, fieldKey, innerCondition.value, 'is'); | ||
} | ||
else if (innerCondition.operator === 'is_not') { | ||
if (innerCondition.value === undefined) { | ||
return undefinedConditionValueToJSONSchema(innerCondition.fieldKey, fieldKey, 'is_not'); | ||
} | ||
jsonCondition = simpleConditionToJSONSchema(innerCondition.fieldKey, fieldKey, innerCondition.value, 'is_not'); | ||
} | ||
else { | ||
throw new Error(`Unsupported conditionally required field operator: ${innerCondition.operator}`); | ||
} | ||
return jsonCondition; | ||
} | ||
export function singleFieldConditionsToJsonSchema(fieldKey, singleFieldConditions) { | ||
let jsonCondition = undefined; | ||
if (singleFieldConditions.conditions.length === 1) { | ||
return fieldConditionSingleDependencyToJsonSchema(singleFieldConditions.conditions[0], fieldKey); | ||
} | ||
const innerConditionArray = []; | ||
singleFieldConditions.conditions.forEach((innerCondition) => { | ||
const dependentFieldKey = innerCondition.fieldKey; | ||
if (dependentFieldKey.split('.').length > 1) { | ||
const [parentKey, childKey] = dependentFieldKey.split('.'); | ||
const conditionToJSON = objectConditionToJSONSchema(parentKey, childKey, fieldKey, innerCondition.value, innerCondition.operator, true); | ||
innerConditionArray.push(conditionToJSON); | ||
const innerIfStatement = singleFieldConditions.match === 'any' ? { anyOf: innerConditionArray } : { allOf: innerConditionArray }; | ||
jsonCondition = { if: innerIfStatement, then: generateThenStatement(fieldKey) }; | ||
return jsonCondition; | ||
} | ||
if (innerCondition.value === undefined) { | ||
innerConditionArray.push(undefinedConditionValueToJSONSchema(innerCondition.fieldKey, fieldKey, innerCondition.operator, true)); | ||
} | ||
else { | ||
const conditionToJSON = simpleConditionToJSONSchema(dependentFieldKey, fieldKey, innerCondition.value, innerCondition.operator, true); | ||
innerConditionArray.push(conditionToJSON); | ||
} | ||
}); | ||
const innerIfStatement = singleFieldConditions.match === 'any' ? { anyOf: innerConditionArray } : { allOf: innerConditionArray }; | ||
jsonCondition = { if: innerIfStatement, then: { required: [fieldKey] } }; | ||
return jsonCondition; | ||
} | ||
export function conditionsToJsonSchema(allFieldConditions) { | ||
const additionalSchema = []; | ||
for (const [fieldKey, singleFieldCondition] of Object.entries(allFieldConditions)) { | ||
const jsonCondition = singleFieldConditionsToJsonSchema(fieldKey, singleFieldCondition); | ||
if (jsonCondition === undefined) { | ||
throw new Error(`Unsupported conditionally required field condition: ${singleFieldCondition}`); | ||
} | ||
if (jsonCondition) { | ||
additionalSchema.push(jsonCondition); | ||
} | ||
} | ||
if (additionalSchema.length === 0) { | ||
return {}; | ||
} | ||
return { allOf: additionalSchema }; | ||
} | ||
export function fieldsToJsonSchema(fields = {}, options, additionalSchema) { | ||
const required = []; | ||
const properties = {}; | ||
const conditions = {}; | ||
for (const [key, field] of Object.entries(fields)) { | ||
@@ -74,5 +228,7 @@ const schemaType = toJsonSchemaType(field.type); | ||
if (schemaType === 'object' && field.properties) { | ||
const propertiesContainsConditionallyRequired = Object.values(field.properties).some((field) => field.required && typeof field.required === 'object'); | ||
if (isMulti) { | ||
schema.items = fieldsToJsonSchema(field.properties, { | ||
additionalProperties: field?.additionalProperties || false | ||
additionalProperties: field?.additionalProperties || false, | ||
omitRequiredSchemas: propertiesContainsConditionallyRequired | ||
}); | ||
@@ -83,11 +239,44 @@ } | ||
...schema, | ||
...fieldsToJsonSchema(field.properties, { additionalProperties: field?.additionalProperties || false }) | ||
...fieldsToJsonSchema(field.properties, { | ||
additionalProperties: field?.additionalProperties || false, | ||
omitRequiredSchemas: propertiesContainsConditionallyRequired | ||
}) | ||
}; | ||
} | ||
for (const [propertyKey, objectField] of Object.entries(field.properties)) { | ||
if (objectField.required === true) { | ||
continue; | ||
} | ||
else if (objectField.required && typeof objectField.required === 'object') { | ||
const dotNotationKey = `${key}.${propertyKey}`; | ||
conditions[dotNotationKey] = objectField.required; | ||
} | ||
} | ||
} | ||
properties[key] = schema; | ||
if (field.required) { | ||
if (field.required === true) { | ||
required.push(key); | ||
} | ||
else if (field.required && typeof field.required === 'object') { | ||
conditions[key] = field.required; | ||
} | ||
} | ||
if (options?.tsType === true) { | ||
return { | ||
$schema: 'http://json-schema.org/schema#', | ||
type: 'object', | ||
additionalProperties: options?.additionalProperties || false, | ||
properties, | ||
required | ||
}; | ||
} | ||
if (options?.omitRequiredSchemas === true) { | ||
return { | ||
$schema: 'http://json-schema.org/schema#', | ||
type: 'object', | ||
additionalProperties: options?.additionalProperties || false, | ||
properties, | ||
...additionalSchema | ||
}; | ||
} | ||
return { | ||
@@ -98,5 +287,7 @@ $schema: 'http://json-schema.org/schema#', | ||
properties, | ||
required | ||
required, | ||
...conditionsToJsonSchema(conditions), | ||
...additionalSchema | ||
}; | ||
} | ||
//# sourceMappingURL=fields-to-jsonschema.js.map |
@@ -37,6 +37,6 @@ import { EventEmitterSlug } from '@segment/action-emitters'; | ||
} | ||
export type AudienceResult = { | ||
export declare type AudienceResult = { | ||
externalId: string; | ||
}; | ||
export type AudienceMode = { | ||
export declare type AudienceMode = { | ||
type: 'realtime'; | ||
@@ -47,3 +47,3 @@ } | { | ||
}; | ||
export type Personas = { | ||
export declare type Personas = { | ||
computation_id: string; | ||
@@ -54,3 +54,3 @@ computation_key: string; | ||
}; | ||
export type CreateAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
export declare type CreateAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
settings: Settings; | ||
@@ -63,3 +63,3 @@ audienceSettings?: AudienceSettings; | ||
}; | ||
export type GetAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
export declare type GetAudienceInput<Settings = unknown, AudienceSettings = unknown> = { | ||
settings: Settings; | ||
@@ -97,3 +97,3 @@ audienceSettings?: AudienceSettings; | ||
} | ||
export type Preset = AutomaticPreset | SpecificEventPreset; | ||
export declare type Preset = AutomaticPreset | SpecificEventPreset; | ||
export interface Subscription { | ||
@@ -144,4 +144,4 @@ name?: string; | ||
} | ||
export type AuthenticationScheme<Settings = any> = BasicAuthentication<Settings> | CustomAuthentication<Settings> | OAuth2Authentication<Settings> | OAuthManagedAuthentication<Settings>; | ||
export type SubscriptionMetadata = { | ||
export declare type AuthenticationScheme<Settings = any> = BasicAuthentication<Settings> | CustomAuthentication<Settings> | OAuth2Authentication<Settings> | OAuthManagedAuthentication<Settings>; | ||
export declare type SubscriptionMetadata = { | ||
actionConfigId?: string; | ||
@@ -148,0 +148,0 @@ destinationConfigId?: string; |
@@ -9,4 +9,4 @@ import { StateContext, Logger, StatsContext, TransactionContext, EngageDestinationCache, ActionHookType, SubscriptionMetadata, RequestFn } from './index'; | ||
import type { ErrorCodes, MultiStatusErrorReporter } from '../errors'; | ||
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | ||
export type MaybePromise<T> = T | Promise<T>; | ||
export declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | ||
export declare type MaybePromise<T> = T | Promise<T>; | ||
export interface Result { | ||
@@ -66,6 +66,6 @@ output?: JSONObject | string | null | undefined; | ||
} | ||
export type FieldTypeName = 'string' | 'text' | 'number' | 'integer' | 'datetime' | 'boolean' | 'password' | 'object'; | ||
type FieldCategory = 'identifier' | 'data' | 'internal' | 'config' | 'sync'; | ||
type FieldInputMethods = 'literal' | 'variable' | 'function' | 'enrichment' | 'freeform'; | ||
type FieldDisplayMode = 'expanded' | 'normal' | 'collapsed'; | ||
export declare type FieldTypeName = 'string' | 'text' | 'number' | 'integer' | 'datetime' | 'boolean' | 'password' | 'object'; | ||
declare type FieldCategory = 'identifier' | 'data' | 'internal' | 'config' | 'sync'; | ||
declare type FieldInputMethods = 'literal' | 'variable' | 'function' | 'enrichment' | 'freeform'; | ||
declare type FieldDisplayMode = 'expanded' | 'normal' | 'collapsed'; | ||
export interface InputFieldJSONSchema { | ||
@@ -83,3 +83,3 @@ label: string; | ||
}>; | ||
required?: boolean; | ||
required?: boolean | DependsOnConditions; | ||
properties?: Record<string, Optional<InputField, 'description'>>; | ||
@@ -113,3 +113,3 @@ format?: 'date' | 'time' | 'date-time' | 'uri' | 'uri-reference' | 'uri-template' | 'email' | 'hostname' | 'ipv4' | 'ipv6' | 'regex' | 'uuid' | 'password' | 'text'; | ||
} | ||
export type Condition = FieldCondition | SyncModeCondition; | ||
export declare type Condition = FieldCondition | SyncModeCondition; | ||
export interface DependsOnConditions { | ||
@@ -119,3 +119,3 @@ match?: 'any' | 'all'; | ||
} | ||
export type FieldValue = string | number | boolean | object | Directive; | ||
export declare type FieldValue = string | number | boolean | object | Directive; | ||
export interface IfDirective { | ||
@@ -140,4 +140,4 @@ '@if': { | ||
} | ||
export type Directive = IfDirective | TemplateDirective | PathDirective | CaseDirective; | ||
export type RequestExtension<Settings, Payload = undefined> = (data: ExecuteInput<Settings, Payload>) => RequestOptions; | ||
export declare type Directive = IfDirective | TemplateDirective | PathDirective | CaseDirective; | ||
export declare type RequestExtension<Settings, Payload = undefined> = (data: ExecuteInput<Settings, Payload>) => RequestOptions; | ||
export interface DeletionPayload { | ||
@@ -147,5 +147,5 @@ userId: ID; | ||
} | ||
export type Deletion<Settings, Return = any> = (request: RequestClient, data: ExecuteInput<Settings, DeletionPayload>) => MaybePromise<Return>; | ||
export declare type Deletion<Settings, Return = any> = (request: RequestClient, data: ExecuteInput<Settings, DeletionPayload>) => MaybePromise<Return>; | ||
export declare const syncModeTypes: readonly ["add", "update", "upsert", "delete", "mirror"]; | ||
export type SyncMode = typeof syncModeTypes[number]; | ||
export declare type SyncMode = typeof syncModeTypes[number]; | ||
export interface SyncModeOption { | ||
@@ -161,3 +161,3 @@ label: string; | ||
} | ||
export type ActionDestinationSuccessResponseType = { | ||
export declare type ActionDestinationSuccessResponseType = { | ||
status: number; | ||
@@ -167,3 +167,3 @@ sent: JSONLikeObject | string; | ||
}; | ||
export type ActionDestinationErrorResponseType = { | ||
export declare type ActionDestinationErrorResponseType = { | ||
status: number; | ||
@@ -175,5 +175,5 @@ errortype?: keyof typeof ErrorCodes; | ||
}; | ||
export type ResultMultiStatusNode = ActionDestinationSuccessResponseType | (ActionDestinationErrorResponseType & { | ||
export declare type ResultMultiStatusNode = ActionDestinationSuccessResponseType | (ActionDestinationErrorResponseType & { | ||
errorreporter: MultiStatusErrorReporter; | ||
}); | ||
export {}; |
@@ -8,3 +8,3 @@ import { CustomError } from 'ts-custom-error'; | ||
} | ||
type RetryableStatusCodes = 408 | 423 | 429 | 500 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 598 | 599; | ||
declare type RetryableStatusCodes = 408 | 423 | 429 | 500 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 598 | 599; | ||
export declare class RetryableError extends CustomError { | ||
@@ -11,0 +11,0 @@ status: RetryableStatusCodes; |
@@ -1,11 +0,11 @@ | ||
export type JSONPrimitive = string | number | boolean | null; | ||
export type JSONValue = JSONPrimitive | JSONObject | JSONArray; | ||
export type JSONObject = { | ||
export declare type JSONPrimitive = string | number | boolean | null; | ||
export declare type JSONValue = JSONPrimitive | JSONObject | JSONArray; | ||
export declare type JSONObject = { | ||
[member: string]: JSONValue; | ||
}; | ||
export type JSONArray = Array<JSONValue>; | ||
export type JSONLike = JSONPrimitive | JSONLikeObject | Array<JSONLike> | Date | undefined; | ||
export type JSONLikeObject = { | ||
export declare type JSONArray = Array<JSONValue>; | ||
export declare type JSONLike = JSONPrimitive | JSONLikeObject | Array<JSONLike> | Date | undefined; | ||
export declare type JSONLikeObject = { | ||
[member: string]: JSONLike; | ||
[member: number]: JSONLike; | ||
}; |
import { JSONObject, JSONLikeObject } from '../json-object'; | ||
export type InputData = { | ||
export declare type InputData = { | ||
[key: string]: unknown; | ||
}; | ||
export type Features = { | ||
export declare type Features = { | ||
[key: string]: boolean; | ||
@@ -7,0 +7,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
type ValueType = 'enrichment' | 'function' | 'literal' | 'variable'; | ||
declare type ValueType = 'enrichment' | 'function' | 'literal' | 'variable'; | ||
export interface DirectiveMetadata { | ||
@@ -22,3 +22,3 @@ _metadata?: { | ||
export declare function isPathDirective(value: FieldValue): value is PathDirective; | ||
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = { | ||
declare type RequireOnlyOne<T, Keys extends keyof T = keyof T> = { | ||
[K in Keys]-?: Partial<Record<Exclude<Keys, K>, undefined>> & Required<Pick<T, K>>; | ||
@@ -94,5 +94,5 @@ }[Keys] & Pick<T, Exclude<keyof T, Keys>>; | ||
export declare function isExcludeWhenNullDirective(value: FieldValue): value is ExcludeWhenNullDirective; | ||
export type Directive = ArrayPathDirective | CaseDirective | IfDirective | LiteralDirective | PathDirective | ReplaceDirective | TemplateDirective | JSONDirective | FlattenDirective | MergeDirective | TransformDirective | ExcludeWhenNullDirective; | ||
export type PrimitiveValue = boolean | number | string | null; | ||
export type FieldValue = Directive | PrimitiveValue | { | ||
export declare type Directive = ArrayPathDirective | CaseDirective | IfDirective | LiteralDirective | PathDirective | ReplaceDirective | TemplateDirective | JSONDirective | FlattenDirective | MergeDirective | TransformDirective | ExcludeWhenNullDirective; | ||
export declare type PrimitiveValue = boolean | number | string | null; | ||
export declare type FieldValue = Directive | PrimitiveValue | { | ||
[key: string]: FieldValue; | ||
@@ -99,0 +99,0 @@ } | FieldValue[] | undefined; |
@@ -27,5 +27,5 @@ /// <reference types="node" /> | ||
} | ||
type MaybePromise<T> = Promise<T> | T; | ||
export type BeforeRequestHook = (options: NormalizedOptions) => MaybePromise<RequestOptions | void>; | ||
export type AfterResponseHook<OutputResponse extends Response = Response> = (request: Request, options: NormalizedOptions, response: Response) => MaybePromise<OutputResponse | void>; | ||
declare type MaybePromise<T> = Promise<T> | T; | ||
export declare type BeforeRequestHook = (options: NormalizedOptions) => MaybePromise<RequestOptions | void>; | ||
export declare type AfterResponseHook<OutputResponse extends Response = Response> = (request: Request, options: NormalizedOptions, response: Response) => MaybePromise<OutputResponse | void>; | ||
export declare class HTTPError extends CustomError { | ||
@@ -32,0 +32,0 @@ request: Request; |
@@ -0,1 +1,2 @@ | ||
import AbortController from 'abort-controller'; | ||
import { CustomError } from 'ts-custom-error'; | ||
@@ -2,0 +3,0 @@ import fetch, { Headers, Request, Response } from './fetch'; |
import { JSONValue } from './json-object'; | ||
export type ID = string | null | undefined; | ||
type CompactMetricType = 'g' | 'c'; | ||
export declare type ID = string | null | undefined; | ||
declare type CompactMetricType = 'g' | 'c'; | ||
interface CompactMetric { | ||
@@ -11,7 +11,7 @@ m: string; | ||
} | ||
export type Integrations = { | ||
export declare type Integrations = { | ||
All?: boolean; | ||
[integration: string]: boolean | undefined; | ||
}; | ||
export type Options = { | ||
export declare type Options = { | ||
integrations?: Integrations; | ||
@@ -18,0 +18,0 @@ anonymousId?: ID; |
{ | ||
"name": "@segment/actions-core", | ||
"description": "Core runtime for Destinations Actions.", | ||
"version": "3.142.1-node20.18", | ||
"version": "3.143.0", | ||
"repository": { | ||
@@ -54,3 +54,3 @@ "type": "git", | ||
"engines": { | ||
"node": "^18.12 || ^20.18" | ||
"node": ">=14" | ||
}, | ||
@@ -77,4 +77,4 @@ "engineStrict": true, | ||
"@types/jest": "^27.0.0", | ||
"@types/json-schema": "^7.0.15", | ||
"benny": "^3.7.1", | ||
"@types/json-schema": "^7.0.7", | ||
"benny": "^3.7.0", | ||
"create-test-server": "^3.0.1", | ||
@@ -86,11 +86,12 @@ "jest": "^27.3.1" | ||
"@segment/action-emitters": "^1.3.6", | ||
"@segment/ajv-human-errors": "^2.13.1-node20.498+9467baa48", | ||
"@segment/destination-subscriptions": "^3.35.1-node20.193+9467baa48", | ||
"@types/node": "^20.17.16", | ||
"@segment/ajv-human-errors": "^2.14.0", | ||
"@segment/destination-subscriptions": "^3.36.0", | ||
"@types/node": "^18.11.15", | ||
"abort-controller": "^3.0.0", | ||
"aggregate-error": "^3.1.0", | ||
"ajv": "^8.17.1", | ||
"ajv": "^8.6.3", | ||
"ajv-formats": "^2.1.1", | ||
"btoa-lite": "^1.0.0", | ||
"cross-fetch": "^3.1.4", | ||
"dayjs": "^1.11.13", | ||
"dayjs": "^1.10.7", | ||
"ts-custom-error": "^3.2.0" | ||
@@ -114,3 +115,3 @@ }, | ||
}, | ||
"gitHead": "ef33be11b9d4069526a6bed96919183993a4c7bb" | ||
"gitHead": "c1b21ce224657b4de0995ed72eea45d1f9336626" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
623914
3.38%8362
4.79%13
8.33%+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated
Updated