import { transformError as sdkTransformError } from '@wix/sdk-runtime/transform-error'; import { renameKeysFromSDKRequestToRESTRequest, renameKeysFromRESTResponseToSDKResponse, } from '@wix/sdk-runtime/rename-all-nested-keys'; import { HttpClient } from '@wix/sdk-types'; import * as ambassadorWixOsTagsV1Tag from './os-tags-v1-tag-tags.http'; export interface Tag { /** * Tag ID. * @readonly */ _id?: string | null; /** * Revision number, which increments by 1 each time the tag is updated. * @readonly */ revision?: string | null; /** * Date and time the tag was created. * @readonly */ _createdDate?: Date | null; /** * Date and time the tag was last updated. * @readonly */ _updatedDate?: Date | null; /** Tag name. */ name?: string | null; /** FQDN of the entity that belongs to this tag. */ fqdn?: string | null; } export enum TagExposure { UNKNOWN = 'UNKNOWN', PRIVATE = 'PRIVATE', } export interface CreateTagRequest { /** The tag to be created. */ tag: Tag; } export interface CreateTagResponse { /** The created tag. */ tag?: Tag; } export interface GetTagRequest { /** The ID of the tag to retrieve. */ tagId: string; } export interface GetTagResponse { /** The requested tag. */ tag?: Tag; } export interface UpdateTagRequest { /** The tag to be updated, which may be partial. */ tag: Tag; } export interface UpdateTagResponse { /** The updated tag. */ tag?: Tag; } export interface DeleteTagRequest { /** ID of the tag to delete. */ tagId: string; } export interface DeleteTagResponse {} export interface ListTagsRequest { /** The Fully Qualified Domain Name (FQDN) to which the tags are associated. Currently supports only eCommerce Orders: `wix.ecom.v1.order`. */ fqdn: string; } export interface ListTagsResponse { /** A list of tags. */ tags?: Tag[]; } export interface DomainEvent extends DomainEventBodyOneOf { createdEvent?: EntityCreatedEvent; updatedEvent?: EntityUpdatedEvent; deletedEvent?: EntityDeletedEvent; actionEvent?: ActionEvent; /** * Unique event ID. * Allows clients to ignore duplicate webhooks. */ _id?: string; /** * Assumes actions are also always typed to an entity_type * Example: wix.stores.catalog.product, wix.bookings.session, wix.payments.transaction */ entityFqdn?: string; /** * This is top level to ease client code dispatching of messages (switch on entity_fqdn+slug) * This is although the created/updated/deleted notion is duplication of the oneof types * Example: created/updated/deleted/started/completed/email_opened */ slug?: string; /** ID of the entity associated with the event. */ entityId?: string; /** Event timestamp in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) format and UTC time. For example: 2020-04-26T13:57:50.699Z */ eventTime?: Date | null; /** * Whether the event was triggered as a result of a privacy regulation application * (for example, GDPR). */ triggeredByAnonymizeRequest?: boolean | null; /** If present, indicates the action that triggered the event. */ originatedFrom?: string | null; /** * A sequence number defining the order of updates to the underlying entity. * For example, given that some entity was updated at 16:00 and than again at 16:01, * it is guaranteed that the sequence number of the second update is strictly higher than the first. * As the consumer, you can use this value to ensure that you handle messages in the correct order. * To do so, you will need to persist this number on your end, and compare the sequence number from the * message against the one you have stored. Given that the stored number is higher, you should ignore the message. */ entityEventSequence?: string | null; } /** @oneof */ export interface DomainEventBodyOneOf { createdEvent?: EntityCreatedEvent; updatedEvent?: EntityUpdatedEvent; deletedEvent?: EntityDeletedEvent; actionEvent?: ActionEvent; } export interface EntityCreatedEvent { entity?: string; } export interface RestoreInfo { deletedDate?: Date | null; } export interface EntityUpdatedEvent { /** * Since platformized APIs only expose PATCH and not PUT we can't assume that the fields sent from the client are the actual diff. * This means that to generate a list of changed fields (as opposed to sent fields) one needs to traverse both objects. * We don't want to impose this on all developers and so we leave this traversal to the notification recipients which need it. */ currentEntity?: string; } export interface EntityDeletedEvent { /** Entity that was deleted */ deletedEntity?: string | null; } export interface ActionEvent { body?: string; } export interface MessageEnvelope { /** App instance ID. */ instanceId?: string | null; /** Event type. */ eventType?: string; /** The identification type and identity data. */ identity?: IdentificationData; /** Stringify payload. */ data?: string; } export interface IdentificationData extends IdentificationDataIdOneOf { /** ID of a site visitor that has not logged in to the site. */ anonymousVisitorId?: string; /** ID of a site visitor that has logged in to the site. */ memberId?: string; /** ID of a Wix user (site owner, contributor, etc.). */ wixUserId?: string; /** ID of an app. */ appId?: string; /** @readonly */ identityType?: WebhookIdentityType; } /** @oneof */ export interface IdentificationDataIdOneOf { /** ID of a site visitor that has not logged in to the site. */ anonymousVisitorId?: string; /** ID of a site visitor that has logged in to the site. */ memberId?: string; /** ID of a Wix user (site owner, contributor, etc.). */ wixUserId?: string; /** ID of an app. */ appId?: string; } export enum WebhookIdentityType { UNKNOWN = 'UNKNOWN', ANONYMOUS_VISITOR = 'ANONYMOUS_VISITOR', MEMBER = 'MEMBER', WIX_USER = 'WIX_USER', APP = 'APP', } export interface CreateTagForAccountRequest { /** The tag to be created. */ tag?: Tag; } export interface CreateTagForAccountResponse { /** The created tag. */ tag?: Tag; } export interface GetTagForAccountRequest { /** The ID of the tag to retrieve. */ tagId?: string; } export interface GetTagForAccountResponse { /** The requested tag. */ tag?: Tag; } export interface UpdateTagForAccountRequest { /** The tag to be updated, which may be partial. */ tag?: Tag; } export interface UpdateTagForAccountResponse { /** The updated tag. */ tag?: Tag; } export interface DeleteTagForAccountRequest { /** ID of the tag to delete. */ tagId?: string; } export interface DeleteTagForAccountResponse {} export interface ListTagsForAccountRequest { /** The Fully Qualified Domain Name (FQDN) to which the tags are associated. Currently supports only eCommerce Orders: `wix.ecom.v1.order`. */ fqdn?: string; } export interface ListTagsForAccountResponse { /** A list of tags. */ tags?: Tag[]; } export interface TagNonNullableFields { exposure: TagExposure; } export interface CreateTagResponseNonNullableFields { tag?: TagNonNullableFields; } export interface GetTagResponseNonNullableFields { tag?: TagNonNullableFields; } export interface UpdateTagResponseNonNullableFields { tag?: TagNonNullableFields; } export interface ListTagsResponseNonNullableFields { tags: TagNonNullableFields[]; } export interface BaseEventMetadata { /** App instance ID. */ instanceId?: string | null; /** Event type. */ eventType?: string; /** The identification type and identity data. */ identity?: IdentificationData; } export interface EventMetadata extends BaseEventMetadata { /** * Unique event ID. * Allows clients to ignore duplicate webhooks. */ _id?: string; /** * Assumes actions are also always typed to an entity_type * Example: wix.stores.catalog.product, wix.bookings.session, wix.payments.transaction */ entityFqdn?: string; /** * This is top level to ease client code dispatching of messages (switch on entity_fqdn+slug) * This is although the created/updated/deleted notion is duplication of the oneof types * Example: created/updated/deleted/started/completed/email_opened */ slug?: string; /** ID of the entity associated with the event. */ entityId?: string; /** Event timestamp in [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) format and UTC time. For example: 2020-04-26T13:57:50.699Z */ eventTime?: Date | null; /** * Whether the event was triggered as a result of a privacy regulation application * (for example, GDPR). */ triggeredByAnonymizeRequest?: boolean | null; /** If present, indicates the action that triggered the event. */ originatedFrom?: string | null; /** * A sequence number defining the order of updates to the underlying entity. * For example, given that some entity was updated at 16:00 and than again at 16:01, * it is guaranteed that the sequence number of the second update is strictly higher than the first. * As the consumer, you can use this value to ensure that you handle messages in the correct order. * To do so, you will need to persist this number on your end, and compare the sequence number from the * message against the one you have stored. Given that the stored number is higher, you should ignore the message. */ entityEventSequence?: string | null; } export interface TagCreatedEnvelope { entity: Tag; metadata: EventMetadata; } /** @webhook * @eventType wix.os.tags.v1.tag_created * @documentationMaturity preview */ export declare function onTagCreated( handler: (event: TagCreatedEnvelope) => void | Promise ): void; export interface TagDeletedEnvelope { entity: Tag; metadata: EventMetadata; } /** @webhook * @eventType wix.os.tags.v1.tag_deleted * @documentationMaturity preview */ export declare function onTagDeleted( handler: (event: TagDeletedEnvelope) => void | Promise ): void; export interface TagUpdatedEnvelope { entity: Tag; metadata: EventMetadata; } /** @webhook * @eventType wix.os.tags.v1.tag_updated * @documentationMaturity preview */ export declare function onTagUpdated( handler: (event: TagUpdatedEnvelope) => void | Promise ): void; /** * Creates a tag. * @param tag - The tag to be created. * @public * @documentationMaturity preview * @requiredField tag * @requiredField tag.fqdn * @requiredField tag.name * @permissionId TAGS.TAG_CREATE * @permissionScope Manage Tags * @permissionScopeId SCOPE.DC-OS.MANAGE-TAGS * @applicableIdentity APP * @returns The created tag. */ export async function createTag(tag: Tag): Promise { // @ts-ignore const { httpClient, sideEffects } = arguments[1] as { httpClient: HttpClient; sideEffects?: any; }; const payload = renameKeysFromSDKRequestToRESTRequest({ tag: tag }); const reqOpts = ambassadorWixOsTagsV1Tag.createTag(payload); sideEffects?.onSiteCall?.(); try { const result = await httpClient.request(reqOpts); sideEffects?.onSuccess?.(result); return renameKeysFromRESTResponseToSDKResponse(result.data)?.tag!; } catch (err: any) { const transformedError = sdkTransformError( err, { spreadPathsToArguments: {}, explicitPathsToArguments: { tag: '$[0]' }, singleArgumentUnchanged: false, }, ['tag'] ); sideEffects?.onError?.(err); throw transformedError; } } /** * Retrieves a tag. * @param tagId - The ID of the tag to retrieve. * @public * @documentationMaturity preview * @requiredField tagId * @permissionId TAGS.TAG_READ * @permissionScope Manage Bookings Services and Settings * @permissionScopeId SCOPE.BOOKINGS.CONFIGURATION * @permissionScope Manage Portfolio * @permissionScopeId SCOPE.PORTFOLIO.MANAGE-PORTFOLIO * @permissionScope Manage Restaurants - all permissions * @permissionScopeId SCOPE.RESTAURANTS.MEGA-SCOPES * @permissionScope Manage Tags * @permissionScopeId SCOPE.DC-OS.MANAGE-TAGS * @permissionScope Read Tags * @permissionScopeId SCOPE.DC-OS.READ-TAGS * @applicableIdentity APP * @returns The requested tag. */ export async function getTag( tagId: string ): Promise { // @ts-ignore const { httpClient, sideEffects } = arguments[1] as { httpClient: HttpClient; sideEffects?: any; }; const payload = renameKeysFromSDKRequestToRESTRequest({ tagId: tagId }); const reqOpts = ambassadorWixOsTagsV1Tag.getTag(payload); sideEffects?.onSiteCall?.(); try { const result = await httpClient.request(reqOpts); sideEffects?.onSuccess?.(result); return renameKeysFromRESTResponseToSDKResponse(result.data)?.tag!; } catch (err: any) { const transformedError = sdkTransformError( err, { spreadPathsToArguments: {}, explicitPathsToArguments: { tagId: '$[0]' }, singleArgumentUnchanged: false, }, ['tagId'] ); sideEffects?.onError?.(err); throw transformedError; } } /** * Updates a tag. * @param _id - Tag ID. * @public * @documentationMaturity preview * @requiredField _id * @requiredField tag * @requiredField tag.name * @requiredField tag.revision * @permissionId TAGS.TAG_UPDATE * @permissionScope Manage Tags * @permissionScopeId SCOPE.DC-OS.MANAGE-TAGS * @applicableIdentity APP * @returns The updated tag. */ export async function updateTag( _id: string | null, tag: UpdateTag ): Promise { // @ts-ignore const { httpClient, sideEffects } = arguments[2] as { httpClient: HttpClient; sideEffects?: any; }; const payload = renameKeysFromSDKRequestToRESTRequest({ tag: { ...tag, id: _id }, }); const reqOpts = ambassadorWixOsTagsV1Tag.updateTag(payload); sideEffects?.onSiteCall?.(); try { const result = await httpClient.request(reqOpts); sideEffects?.onSuccess?.(result); return renameKeysFromRESTResponseToSDKResponse(result.data)?.tag!; } catch (err: any) { const transformedError = sdkTransformError( err, { spreadPathsToArguments: { tag: '$[1]' }, explicitPathsToArguments: { 'tag.id': '$[0]' }, singleArgumentUnchanged: false, }, ['_id', 'tag'] ); sideEffects?.onError?.(err); throw transformedError; } } export interface UpdateTag { /** * Tag ID. * @readonly */ _id?: string | null; /** * Revision number, which increments by 1 each time the tag is updated. * @readonly */ revision?: string | null; /** * Date and time the tag was created. * @readonly */ _createdDate?: Date | null; /** * Date and time the tag was last updated. * @readonly */ _updatedDate?: Date | null; /** Tag name. */ name?: string | null; /** FQDN of the entity that belongs to this tag. */ fqdn?: string | null; } /** * Deletes a tag. * @param tagId - ID of the tag to delete. * @public * @documentationMaturity preview * @requiredField tagId * @permissionId TAGS.TAG_DELETE * @permissionScope Manage Tags * @permissionScopeId SCOPE.DC-OS.MANAGE-TAGS * @applicableIdentity APP */ export async function deleteTag(tagId: string): Promise { // @ts-ignore const { httpClient, sideEffects } = arguments[1] as { httpClient: HttpClient; sideEffects?: any; }; const payload = renameKeysFromSDKRequestToRESTRequest({ tagId: tagId }); const reqOpts = ambassadorWixOsTagsV1Tag.deleteTag(payload); sideEffects?.onSiteCall?.(); try { const result = await httpClient.request(reqOpts); sideEffects?.onSuccess?.(result); } catch (err: any) { const transformedError = sdkTransformError( err, { spreadPathsToArguments: {}, explicitPathsToArguments: { tagId: '$[0]' }, singleArgumentUnchanged: false, }, ['tagId'] ); sideEffects?.onError?.(err); throw transformedError; } } /** * Retrieves a list of tags. * @param fqdn - The Fully Qualified Domain Name (FQDN) to which the tags are associated. Currently supports only eCommerce Orders: `wix.ecom.v1.order`. * @public * @documentationMaturity preview * @requiredField fqdn * @permissionId TAGS.TAG_READ * @permissionScope Manage Bookings Services and Settings * @permissionScopeId SCOPE.BOOKINGS.CONFIGURATION * @permissionScope Manage Portfolio * @permissionScopeId SCOPE.PORTFOLIO.MANAGE-PORTFOLIO * @permissionScope Manage Restaurants - all permissions * @permissionScopeId SCOPE.RESTAURANTS.MEGA-SCOPES * @permissionScope Manage Tags * @permissionScopeId SCOPE.DC-OS.MANAGE-TAGS * @permissionScope Read Tags * @permissionScopeId SCOPE.DC-OS.READ-TAGS * @applicableIdentity APP */ export async function listTags( fqdn: string ): Promise { // @ts-ignore const { httpClient, sideEffects } = arguments[1] as { httpClient: HttpClient; sideEffects?: any; }; const payload = renameKeysFromSDKRequestToRESTRequest({ fqdn: fqdn }); const reqOpts = ambassadorWixOsTagsV1Tag.listTags(payload); sideEffects?.onSiteCall?.(); try { const result = await httpClient.request(reqOpts); sideEffects?.onSuccess?.(result); return renameKeysFromRESTResponseToSDKResponse(result.data)!; } catch (err: any) { const transformedError = sdkTransformError( err, { spreadPathsToArguments: {}, explicitPathsToArguments: { fqdn: '$[0]' }, singleArgumentUnchanged: false, }, ['fqdn'] ); sideEffects?.onError?.(err); throw transformedError; } }