﻿<ConnectionManager Name="IFS Cloud" RuntimeVersion="" Help="http://www.cozyroc.com/ssis/ifs-cloud-connection" xmlns="http://www.cozyroc.com/schema/rcm-config-1.0.xsd">
	<Service EndPoint="https://[Domain]/main/ifsapplications/projection/v1" />

	<Authentication>
		<Documentation>https://docs.ifs.com/techdocs/21r2/010_overview/240_integration/400_rest_apis/</Documentation>

		<User>
			<Parameter Name="client_id">
				<Documentation>Required. Specify the client_id.</Documentation>
			</Parameter>
			<Parameter Name="client_secret">
				<Documentation>Required. Specify application client secret.</Documentation>
			</Parameter>
			<Parameter Name="scope" Default="openid">
				<Documentation>Required. Specify the scope.</Documentation>
			</Parameter>
		</User>

		<Test Url="/MaintInventoryPartHandling.svc/MaintenanceInvPartSet" />

		<Token Url="{{=new Uri(connection.serverHost).authority()}}/auth/realms/preifs/protocol/openid-connect/token" Result="{{=response.access_token}}">
			<Documentation>https://dsj23.me/2021/01/08/ifs-authentication-flow-with-oauth-and-openid-connect/</Documentation>

			<Parameters>
				<Parameter Name="grant_type" Value="client_credentials" />
				<Parameter Name="client_id" Value="{{=token.client_id}}" />
				<Parameter Name="client_secret" Value="{{=token.client_secret}}" />
				<Parameter Name="scope" Value="{{=token.scope}}" />
			</Parameters>

			<Refresh Url="{{=new Uri(connection.serverHost).authority()}}/auth/realms/preifs/protocol/openid-connect/token" Method="POST" Result="{{=response.access_token}}" Expiration="{{=Date.now() + (response.expires_in - 300) * 1000}}">
				<Parameters>
					<Parameter Name="grant_type" Value="client_credentials" />
					<Parameter Name="client_id" Value="{{=token.client_id}}" />
					<Parameter Name="client_secret" Value="{{=token.client_secret}}" />
					<Parameter Name="scope" Value="{{=token.scope}}" />
				</Parameters>
			</Refresh>
		</Token>

		<Parameters>
			<Parameter Name="Authorization" Value="Bearer {{=token.Access}}" Type="HttpHeader" />
		</Parameters>
	</Authentication>

	<Resources>
		<Template>
			<Field Name="ShortText" DataType="DT_WSTR" Length="255" />
			<Field Name="LongText" DataType="DT_WSTR" Length="1000" />
			<Field Name="DateTime" DataType="DT_DBTIMESTAMP" />
			<Field Name="Date" DataType="DT_DBDATE" />

			<Resource Name="Base">
				<Read>
					<Parameters>
						<Parameter Name="$skip" Value="{{=parameters.iterator}}" />
						<Parameter Name="$top" Value="{{=parameters.batchSize}}" />
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
					</Parameters>

					<Iterator>
						<Next Value="{{=parseInt(parameters.iterator || 0) + parameters.batchSize}}">
							<Documentation>https://docs.ifs.com/techdocs/21r2/050_development/050_development_tools/022_user_interface/030_aurena_dev/140_resources/100_odata_provider/1000_supported_functionalities/#top_and_skip</Documentation>
						</Next>
					</Iterator>
				</Read>

				<Create Method="POST">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=item}}" Type="Body" />
					</Parameters>
				</Create>

				<Update Method="PUT">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=item}}" Type="Body" />
					</Parameters>
				</Update>

				<Delete Method="DELETE" />
			</Resource>
		</Template>

	</Resources>
	<Script>
		<Module Name="Main">
			<![CDATA[
require('underscore');
require('Uri');

]]>
		</Module>
	</Script>
</ConnectionManager>