Skip to content

Commit

Permalink
Add 'samples/react-application-webhooks-notification/' from commit '4…
Browse files Browse the repository at this point in the history
…c4111399e1496f9ade012ac0e1afcc7d1902323'

git-subtree-dir: samples/react-application-webhooks-notification
git-subtree-mainline: ee1455d
git-subtree-split: 4c41113
  • Loading branch information
giuleon committed Nov 5, 2017
2 parents ee1455d + 4c41113 commit de2974e
Show file tree
Hide file tree
Showing 31 changed files with 1,002 additions and 0 deletions.
25 changes: 25 additions & 0 deletions samples/react-application-webhooks-notification/.editorconfig
@@ -0,0 +1,25 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# change these settings to your own preference
indent_style = space
indent_size = 2

# we recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[{package,bower}.json]
indent_style = space
indent_size = 2
32 changes: 32 additions & 0 deletions samples/react-application-webhooks-notification/.gitignore
@@ -0,0 +1,32 @@
# Logs
logs
*.log
npm-debug.log*

# Dependency directories
node_modules

# Build generated files
dist
lib
solution
temp
*.sppkg

# Coverage directory used by tools like istanbul
coverage

# OSX
.DS_Store

# Visual Studio files
.ntvs_analysis.dat
.vs
bin
obj

# Resx Generated Code
*.resx.ts

# Styles Generated Code
*.scss.ts
@@ -0,0 +1,5 @@
{
"recommendations": [
"msjsdiag.debugger-for-chrome"
]
}
@@ -0,0 +1,42 @@
{
/**
Install Chrome Debugger Extension for Visual Studio Code
to debug your components with the Chrome browser:
https://aka.ms/spfx-debugger-extensions
*/
"version": "0.2.0",
"configurations": [{
"name": "Local workbench",
"type": "chrome",
"request": "launch",
"url": "https://localhost:4321/temp/workbench.html",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../../src/*": "${webRoot}/src/*"
},
"runtimeArgs": [
"--remote-debugging-port=9222"
]
},
{
"name": "Hosted workbench",
"type": "chrome",
"request": "launch",
"url": "https://giuleon.sharepoint.com/sites/demo/Lists/FieldCustomizer/AllItems.aspx?loadSPFX=true&debugManifestsFile=https://localhost:4321/temp/manifests.js&customActions={'c0c009bd-5299-4c13-9826-9068022ce804':{'location':'ClientSideExtension.ApplicationCustomizer','properties':{'Top':'Top area of the page'}}}",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../src/*": "${webRoot}/src/*",
"webpack:///../../../../../src/*": "${webRoot}/src/*"
},
"runtimeArgs": [
"--remote-debugging-port=9222",
"-incognito"
]
}
]
}
@@ -0,0 +1,75 @@
// Place your settings in this file to overwrite default and user settings.
{
// Configure glob patterns for excluding files and folders in the file explorer.
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/bower_components": true,
"**/coverage": true,
"**/lib-amd": true,
"src/**/*.scss.ts": true
},
"typescript.tsdk": ".\\node_modules\\typescript\\lib",
"json.schemas": [
{
"fileMatch": [
"/config/config.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/configJson/schemas/config-v1.schema.json"
},
{
"fileMatch": [
"/config/copy-assets.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/copyAssets/copy-assets.schema.json"
},
{
"fileMatch": [
"/config/deploy-azure-storage.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/deployAzureStorage/deploy-azure-storage.schema.json"
},
{
"fileMatch": [
"/config/package-solution.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/packageSolution/package-solution.schema.json"
},
{
"fileMatch": [
"/config/serve.json"
],
"url": "./node_modules/@microsoft/gulp-core-build-serve/lib/serve.schema.json"
},
{
"fileMatch": [
"/config/tslint.json"
],
"url": "./node_modules/@microsoft/gulp-core-build-typescript/lib/schemas/tslint.schema.json"
},
{
"fileMatch": [
"/config/write-manifests.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/writeManifests/write-manifests.schema.json"
},
{
"fileMatch": [
"/config/configure-webpack.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/configureWebpack/configure-webpack.schema.json"
},
{
"fileMatch": [
"/config/configure-external-bundling-webpack.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/configureWebpack/configure-webpack-external-bundling.schema.json"
},
{
"fileMatch": [
"/copy-static-assets.json"
],
"url": "./node_modules/@microsoft/sp-build-core-tasks/lib/copyStaticAssets/copy-static-assets.schema.json"
}
]
}
8 changes: 8 additions & 0 deletions samples/react-application-webhooks-notification/.yo-rc.json
@@ -0,0 +1,8 @@
{
"@microsoft/generator-sharepoint": {
"version": "1.3.4",
"libraryName": "spfx-extension-react-webhooks-notification",
"libraryId": "7d58bb4d-d053-4ae0-8fb8-9ff8c390fe46",
"environment": "spo"
}
}
@@ -0,0 +1,118 @@
#################
# Configuration #
#################
$catalogSite = "https://giuleon.sharepoint.com/sites/apps" # => App Catalog site
$catalogRelativePath = "sites/apps/AppCatalog" # => App Catalog relative url
#######
# End #
#######

# Get Web Request
function GetRequest ($apiUrl, $webSession) {
return Invoke-WebRequest -Uri $apiUrl -Method Get -WebSession $webSession
}

# Post Web Request
function PostRequest($apiUrl, $webSession, $body) {
return Invoke-WebRequest -Uri $apiUrl -Body $body -Method Post -WebSession $webSession

}

# Settting the right parameters value
function setXmlMapping($xmlBody, $siteId, $webId, $listId, $fileId, $fileVersion, $skipDeployment) {
# Replace the random token with a random guid
$randomGuid = [guid]::NewGuid()
if($skipDeployment -eq $True){
$skipDeployment = "true"
}
else{
$skipDeployment = "false"
}
$xmlBody = [regex]::replace($xmlBody, "{randomId}", $randomGuid)
# Replace the site ID token with the actual site ID string
$xmlBody = [regex]::replace($xmlBody, "{siteId}", $siteId)
# Replace the web ID token with the actual web ID string
$xmlBody = [regex]::replace($xmlBody, "{webId}", $webId)
# Replace the list ID token with the actual list ID string
$xmlBody = [regex]::replace($xmlBody, "{listId}", $listId)
# Replace the item ID token with the actual item ID number
$xmlBody = [regex]::replace($xmlBody, "{itemId}", $fileId)
# Replace the file version token with the actual file version number
$xmlBody = [regex]::replace($xmlBody, "{fileVersion}", $fileVersion)
# Replace the skipFeatureDeployment token with the skipFeatureDeployment option
$xmlBody = [regex]::replace($xmlBody, "{skipFeatureDeployment}", $skipDeployment)
return $xmlBody;
}

Write-Host ***************************************** -ForegroundColor Yellow
Write-Host * Uploading the sppkg on the AppCatalog * -ForegroundColor Yellow
Write-Host ***************************************** -ForegroundColor Yellow
$packageConfig = Get-Content -Raw -Path .\config\package-solution.json | ConvertFrom-Json
$packagePath = Join-Path "sharepoint/" $packageConfig.paths.zippedPackage -Resolve
$skipFeatureDeployment = $packageConfig.solution.skipFeatureDeployment

# Connect-PnPOnline $catalogSite -Credentials (Get-Credential)
Connect-PnPOnline $catalogSite -Credentials giuleon
Add-PnPFile -Path $packagePath -Folder "AppCatalog"

Write-Host *************************************************** -ForegroundColor Yellow
Write-Host * The SPFx solution has been succesfully uploaded to the AppCatalog * -ForegroundColor Yellow
Write-Host *************************************************** -ForegroundColor Yellow

# Connect to SharePoint Online
$targetSite = "https://giuleon.sharepoint.com/sites/apps"
$targetSiteUri = [System.Uri]$targetSite

# Retrieve the client credentials and the related Authentication Cookies
$context = (Get-PnPWeb).Context
$credentials = $context.Credentials
$authenticationCookies = $credentials.GetAuthenticationCookie($targetSiteUri, $true)

# Set the Authentication Cookies and the Accept HTTP Header
$webSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$webSession.Cookies.SetCookies($targetSiteUri, $authenticationCookies)
$webSession.Headers.Add("Accept", "application/json;odata=verbose")

$apiUrl = $catalogSite + "/_api/contextinfo?$"+"select=FormDigestValue"
$result = PostRequest -apiUrl $apiUrl -webSession $webSession
$formDigest = $result.Content | ConvertFrom-Json
Write-Host "FormDigestValue - " $formDigest.d.GetContextWebInformation.FormDigestValue
$formDigest = $formDigest.d.GetContextWebInformation.FormDigestValue
$webSession.Headers.Add("X-RequestDigest", $formDigest)

# Set request variables
$apiUrl = "$targetSite" + "/_api/site?$"+"select=Id"

# Make the REST request
$webRequest = GetRequest -apiUrl $apiUrl -webSession $webSession # Invoke-WebRequest -Uri $apiUrl -Method Get -WebSession $webSession
$response = $webRequest.Content | ConvertFrom-Json
$siteId = $response.d.Id
Write-Host "Site Id - " $response.d.Id

# Retrieving webId and listId
$apiUrl = "$targetSite" + "/_api/web/getList('$catalogRelativePath')?$"+"select=Id,ParentWeb/Id`&`$"+"expand=ParentWeb"
$webRequest = GetRequest -apiUrl $apiUrl -webSession $webSession # Invoke-WebRequest -Uri $apiUrl -Method Get -WebSession $webSession
$response = $webRequest.Content | ConvertFrom-Json
$webId = $response.d.ParentWeb.Id
$listId = $response.d.Id
Write-Host "Web Id - " $webId " / List Id - " + $listId

# Get the ListItemAllFields Id and Version
$fileName = $packageConfig.paths.zippedPackage.Substring($packageConfig.paths.zippedPackage.LastIndexOf("/")+1)
$apiUrl = "$targetSite" + "/_api/web/GetFolderByServerRelativeUrl('AppCatalog')/Files('$fileName')?$"+"expand=ListItemAllFields`&`$" + "select=ListItemAllFields/ID,ListItemAllFields/owshiddenversion"
$webRequest = GetRequest -apiUrl $apiUrl -webSession $webSession
$response = $webRequest.Content -replace '"id":', '"id_":' | ConvertFrom-Json
$fileId = $response.d.ListItemAllFields.id_
$fileVersion = $response.d.ListItemAllFields.owshiddenversion
Write-Host "ListItem Id - " $fileId " / Version - " $fileVersion

# Read the xml
$xmlBody = Get-Content DeploySPFxToAppCatalogRequestBody.xml -Encoding UTF8
$xmlBody = setXmlMapping -xmlBody $xmlBody -siteId $siteId -webId $webId -listId $listId -fileId $fileId -fileVersion $fileVersion -skipDeployment $skipFeatureDeployment
Write-Host "deployment in progress....."

# Deploy the sspkg
$webSession.Headers.Add("Content-type", "application/xml")
$apiUrl = $catalogSite + "/_vti_bin/client.svc/ProcessQuery"
$result = PostRequest -apiUrl $apiUrl -webSession $webSession -body $xmlBody
Write-Host $result

0 comments on commit de2974e

Please sign in to comment.