UNPKG

134 kBSource Map (JSON)View Raw
1{"version":3,"sources":["webpack://Ketting/webpack/bootstrap","webpack://Ketting/./src/utils/url.web.ts","webpack://Ketting/./src/link.ts","webpack://Ketting/./src/representor/base.ts","webpack://Ketting/./src/resource.ts","webpack://Ketting/./src/utils/fetch-helper.ts","webpack://Ketting/./node_modules/fetch-mw-oauth2/dist/error.js","webpack://Ketting/./src/index.ts","webpack://Ketting/./src/ketting.ts","webpack://Ketting/./src/representor/hal.ts","webpack://Ketting/./node_modules/uri-template/index.js","webpack://Ketting/./node_modules/uri-template/lib/classes.js","webpack://Ketting/./node_modules/uri-template/lib/encoders.js","webpack://Ketting/./node_modules/pct-encode/index.js","webpack://Ketting/./src/representor/html.web.ts","webpack://Ketting/./src/representor/jsonapi.ts","webpack://Ketting/./node_modules/http-link-header/lib/link.js","webpack://Ketting/./src/followable-promise.ts","webpack://Ketting/./src/http-error.ts","webpack://Ketting/(webpack)/buildin/global.js","webpack://Ketting/./node_modules/fetch-mw-oauth2/dist/index.js","webpack://Ketting/./node_modules/fetch-mw-oauth2/dist/fetch-wrapper.js","webpack://Ketting/./node_modules/fetch-mw-oauth2/dist/base64.web.js","webpack://Ketting/./node_modules/fetch-mw-oauth2/dist/util.js","webpack://Ketting/./src/utils/base64.web.ts"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","base","relative","URL","toString","doc","document","oldBase","getElementsByTagName","oldHref","href","docHead","head","ourBase","appendChild","createElement","resolver","resolvedUrl","removeChild","url","host","properties","this","templated","title","type","resolve","context","variables","expanded","uriTemplate","parse","expand","uri","contentType","body","links","embedded","client","inFlightRefresh","repr","preferPushRels","Set","representation","contentTypes","mime","params","method","JSON","stringify","headers","getAcceptHeader","fetchAndThrow","response","has","go","Accept","size","Array","from","join","Prefer","then","result1","text","result2","Error","getRepresentor","httpLinkHeader","httpLink","LinkHeader","refs","rel","split","push","keys","filter","item","add","async","res","rej","length","resource","reason","map","link","refresh","input","init","newInit","undefined","Request","Headers","credentials","cache","redirect","referrer","integrity","TypeError","mergeHeaders","request","fetch","ok","headerSets","result","headerSet","set","index","options","onBeforeRequest","oAuth2Buckets","Map","innerFetch","global","requestInfo","requestInit","domainOptions","getDomainOptions","inits","newHeaders","assign","mergeInit","fetchInit","version","fetchAuth","match","auth","authBucket","matchStr","entries","matchRegex","part","replace","RegExp","test","authOptions","doFetch","base64","encode","userName","password","token","OAuthError","message","oauth2Code","httpCode","super","default","bookMark","resourceCache","representor","q","fetchHelper","beforeRequest","getResource","follow","indexOf","trim","find","includes","clearCache","Hal","_links","parseHalLinks","_embedded","parseHalEmbedded","relType","isArray","parseHalLink","embeddedItem","self","quote","escape","startRule","parseFunctions","result0","pos0","pos","parse_nonexpression","parse_expression","Template","parse_op","substr","reportFailures","matchFailed","parse_paramList","parse_param","parse_cut","parse_listMarker","parse_substr","parse_extension","rightmostFailuresPos","rightmostFailuresExpected","failure","result3","pos1","op","charCodeAt","expression","charAt","pos2","pos3","hd","rst","offset","unshift","chars","clm","e","explode","listMarker","cut","extended","digits","parseInt","cls","Math","max","found","errorPosition","line","column","seenCR","ch","computeErrorPosition","SyntaxError","expected","sort","lastExpected","cleanExpected","cleanupExpected","toSource","_source","expectedHumanized","slice","buildMessage","FormContinuationExpression","FormStartExpression","FragmentExpression","LabelExpression","NamedExpression","PathParamExpression","PathSegmentExpression","ReservedExpression","SimpleExpression","encoders","__bind","fn","me","apply","arguments","__hasProp","__extends","child","parent","ctor","constructor","__super__","pieces","_this","expressions","prefix","shift","forEach","suffix","vars","expr","toJSON","_super","explodeArray","stringifySingle","param","empty","array","v","sep","definedPairs","explodeObject","_expandPair","first","named","allow","string","k","substring","_results","defined","pair","pairs","vv","_i","_len","pctEncode","regexp","String","encoded","toUpperCase","Html","DOMParser","parseFromString","linkFromTags","htmlDoc","elements","node","rels","getAttribute","JsonApi","parseJsonApiLinks","parseJsonApiCollection","baseHref","linkValue","parseJsonApiLink","data","member","selfLink","COMPATIBLE_ENCODING_PATTERN","WS_TRIM_PATTERN","WS_CHAR_PATTERN","WS_FOLD_PATTERN","DELIMITER_PATTERN","WS_DELIMITER_PATTERN","STATE","IDLE","URI","ATTR","hasWhitespace","skipWhitespace","needsQuotes","Link","attr","toLowerCase","state","ref","end","attrValue","isSingleOccurenceAttr","parseExtendedValue","reduce","formatAttribute","isCompatibleEncoding","isTokenAttr","escapeQuotes","parts","exec","language","encoding","decodeURIComponent","formatExtendedAttribute","Buffer","isBuffer","encodeURIComponent","FollowablePromise","executor","realPromise","Promise","onResolve","onReject","catch","reject","err","followAll","HttpError","status","Problem","problemBody","json","g","Function","window","fetch_wrapper_1","fetchMwOAuth2","OAuth2","error_1","OAuth2Error","__importDefault","mod","base64_1","util_1","requestWithBearerToken","accessToken","expiresAt","refreshToken","getAccessToken","clone","Date","now","previousToken","grant_type","refresh_token","clientSecret","client_id","clientId","grantType","scope","username","code","redirect_uri","redirectUri","basicAuthStr","Authorization","authResult","tokenEndpoint","objToQueryString","jsonResult","errorMessage","error","error_description","access_token","expires_in","onTokenUpdate","btoa"],"mappings":"wBACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QA0Df,OArDAF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,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ACxB3B,UAAWuB,EAAWK,WAAaxB,KAAKC,MAAiC,IAAxBkB,EAAWK,WAAqB,KACjF3B,aAAcsB,EAAWf,cAAgBe,EAAWf,cAAgB,MAEpE/W,KAAKuF,QAAQ6S,eACbpY,KAAKuF,QAAQ6S,cAAcpY,KAAKwH,OAE7BxH,KAAKwH,MAAM8O,e,6BC7I1BjZ,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,IAOtDnB,EAAQ4K,OAHR,SAAgBnD,GACZ,OAAOmU,KAAKnU,K,6BCLhB7G,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,IAgBtDnB,EAAQob,iBAXR,SAA0B3T,GACtB,OAAO7G,OAAOuJ,QAAQ1C,GAAOH,IAAI,EAAE7F,EAAKN,UACtByG,IAAVzG,EAEO,GAGA6W,mBAAmBvW,GAAO,IAAMuW,mBAAmB7W,IAE/D0E,KAAK,O,8ECZZ,kBAAuB4B,GAErB,OAAOmU,KAAKnU,K","file":"ketting.min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 7);\n","type UrlParts = {\n host?: string,\n};\n\n/**\n * Resolves a relative url using another url.\n *\n * This is the browser-based version.\n */\nexport function resolve(base: string, relative: string): string {\n\n // If the URL object is supported, we prefer that.\n if (typeof URL !== 'undefined') {\n return (new URL(relative, base).toString());\n }\n\n // Code taken from this gist:;\n // https://gist.github.com/johan/3915545#file-resolveurl-js\n\n const doc = document;\n const oldBase = doc.getElementsByTagName('base')[0];\n const oldHref = oldBase && oldBase.href;\n const docHead = doc.head || doc.getElementsByTagName('head')[0];\n const ourBase = oldBase || docHead.appendChild(doc.createElement('base'));\n const resolver = doc.createElement('a');\n\n ourBase.href = base;\n resolver.href = relative;\n const resolvedUrl = resolver.href; // browser magic at work here\n\n if (oldBase) {\n oldBase.href = oldHref;\n } else {\n docHead.removeChild(ourBase);\n }\n return resolvedUrl;\n\n}\n\n/**\n * Parses a url in multiple components.\n *\n * This is the browser-based version.\n */\nexport function parse(url: string): UrlParts {\n\n const urlObj = new URL(url);\n return {\n host: urlObj.host,\n };\n\n}\n","import * as uriTemplate from 'uri-template';\nimport { resolve } from './utils/url';\n\ntype LinkInit = {\n context: string,\n href: string,\n name?: string,\n rel: string,\n templated?: boolean,\n title?: string,\n type?: string,\n};\n\n/**\n * The Link object represents a hyperlink.\n */\nexport default class Link {\n\n /**\n * The base href of the parent document. Used for expanding relative links.\n */\n context: string;\n\n /**\n * The URI of the link. Might be relative\n */\n href: string;\n\n /**\n * The name for a link. This might be used to disambiguate the link.\n *\n * If you're looking at this, chances are that you might want 'title'\n * instead.\n */\n name?: string;\n\n /**\n * The relationship type\n */\n rel: string;\n\n /**\n * Is it a URI template or not?\n */\n templated: boolean;\n\n /**\n * A human-readable label for the link.\n */\n title: string | null;\n\n /**\n * A mimetype\n */\n type: string | null;\n\n constructor(properties: LinkInit) {\n\n this.templated = false;\n this.title = null;\n this.type = null;\n for (const key of ['context', 'href', 'name', 'rel', 'templated', 'title', 'type']) {\n if ((<any> properties)[key]) {\n (<any> this)[key] = (<any> properties)[key];\n }\n }\n\n }\n\n\n /**\n * Returns the absolute link url, based on it's base and relative url.\n */\n resolve(): string {\n\n return resolve(this.context, this.href);\n\n }\n\n /**\n * Expands a link template (RFC6570) and resolves the uri\n *\n * @param {object} variables - A list of variables to expand the link with.\n * @returns {string}\n */\n expand(variables: object): string {\n\n if (!this.templated) {\n return resolve(this.context, this.href);\n } else {\n const templ = uriTemplate.parse(this.href);\n const expanded = templ.expand(variables);\n return resolve(this.context, expanded);\n }\n\n }\n\n}\n","import Link from '../link';\n\n\n/**\n * The Representation class is basically a 'body' of a request\n * or response.\n *\n * This is base class for a representation.\n */\nexport default class Representation {\n\n body: any;\n contentType: string;\n embedded: {\n [uri: string]: object\n };\n links: Link[];\n uri: string;\n\n constructor(uri: string, contentType: string, body: any) {\n\n this.uri = uri;\n this.contentType = contentType;\n this.body = body;\n this.links = [];\n this.embedded = {};\n\n }\n\n}\n","import * as LinkHeader from 'http-link-header';\nimport FollowablePromise from './followable-promise';\nimport problemFactory from './http-error';\nimport Ketting from './ketting';\nimport Link from './link';\nimport Representation from './representor/base';\nimport { mergeHeaders } from './utils/fetch-helper';\nimport { resolve } from './utils/url';\n\n/**\n * A 'resource' represents an endpoint on the server.\n *\n * The endpoint has a uri, you might for example be able to GET its\n * presentation.\n *\n * A resource may also have a list of links on them, pointing to other\n * resources.\n *\n * @param {Client} client\n * @param {string} uri\n * @constructor\n */\nexport default class Resource<T = any> {\n\n /**\n * Reference to the main Client\n */\n client: Ketting;\n\n /**\n * The current representation, or body of the resource.\n */\n repr: Representation | null;\n\n /**\n * The uri of the resource\n */\n uri: string;\n\n /**\n * A default mimetype for the resource.\n *\n * This mimetype is used for PUT and POST requests by default.\n * The mimetype is sniffed in a few different ways.\n *\n * If a GET request is done, and the GET request had a mimetype it will\n * be used to set this value.\n *\n * It's also possible for resources to get a mimetype through a link.\n *\n * If the mimetype was \"null\" when doing the request, the chosen mimetype\n * will come from the first item in Client.resourceTypes\n */\n contentType: string | null;\n\n private inFlightRefresh: Promise<any> = null;\n\n /**\n * A list of rels that should be added to a Prefer-Push header.\n */\n private preferPushRels: Set<string>;\n\n constructor(client: Ketting, uri: string, contentType: string = null) {\n\n this.client = client;\n this.uri = uri;\n this.repr = null;\n this.contentType = contentType;\n this.preferPushRels = new Set();\n\n }\n\n /**\n * Fetches the resource representation.\n * Returns a promise that resolves to a parsed json object.\n */\n async get(): Promise<T> {\n\n const r = await this.representation();\n return r.body;\n\n }\n\n /**\n * Updates the resource representation with a new JSON object.\n */\n async put(body: T): Promise<void> {\n\n const contentType = this.contentType || this.client.contentTypes[0].mime;\n const params = {\n method: 'PUT',\n body: JSON.stringify(body),\n headers: {\n 'Content-Type': contentType,\n 'Accept' : this.contentType ? this.contentType : this.client.getAcceptHeader()\n },\n };\n await this.fetchAndThrow(params);\n\n }\n\n /**\n * Updates the resource representation with a new JSON object.\n */\n async delete(): Promise<void> {\n\n await this.fetchAndThrow({ method: 'DELETE' });\n\n }\n\n /**\n * Sends a POST request to the resource.\n *\n * This function assumes that POST is used to create new resources, and\n * that the response will be a 201 Created along with a Location header that\n * identifies the new resource location.\n *\n * This function returns a Promise that resolves into the newly created\n * Resource.\n *\n * If no Location header was given, it will resolve still, but with an empty\n * value.\n */\n async post(body: object): Promise<Resource|null> {\n\n const contentType = this.contentType || this.client.contentTypes[0].mime;\n const response = await this.fetchAndThrow(\n {\n method: 'POST',\n body: JSON.stringify(body),\n headers: {\n 'Content-Type': contentType,\n }\n }\n );\n\n if (response.headers.has('location')) {\n return this.go(<string> response.headers.get('location'));\n }\n return null;\n\n }\n\n /**\n * Sends a PATCH request to the resource.\n *\n * This function defaults to a application/json content-type header.\n */\n async patch(body: object): Promise<void> {\n\n await this.fetchAndThrow(\n {\n method: 'PATCH',\n body: JSON.stringify(body),\n headers: {\n 'Content-Type' : 'application/json'\n }\n }\n );\n\n }\n\n /**\n * Refreshes the representation for this resource.\n *\n * This function will return the a parsed JSON object, like the get\n * function does.\n *\n * @return {object}\n */\n async refresh(): Promise<T> {\n\n let response: Response;\n let body: string;\n\n // If 2 systems request a 'refresh' at the exact same time, this mechanism\n // will coalesc them into one.\n if (!this.inFlightRefresh) {\n\n const headers: { [name: string]: string } = {\n Accept: this.contentType ? this.contentType : this.client.getAcceptHeader()\n };\n\n if (this.preferPushRels.size > 0) {\n headers['Prefer-Push'] = Array.from(this.preferPushRels).join(' ');\n headers.Prefer = 'transclude=\"' + Array.from(this.preferPushRels).join(';') + '\"';\n }\n\n this.inFlightRefresh = this.fetchAndThrow({\n method: 'GET' ,\n headers\n }).then( result1 => {\n response = result1;\n return response.text();\n })\n .then( result2 => {\n body = result2;\n return [response, body];\n });\n\n try {\n await this.inFlightRefresh;\n } finally {\n this.inFlightRefresh = null;\n }\n\n } else {\n // Something else asked for refresh, so we piggypack on it.\n [response, body] = await this.inFlightRefresh;\n\n }\n\n const contentType = response.headers.get('Content-Type');\n if (!contentType) {\n throw new Error('Server did not respond with a Content-Type header');\n }\n this.repr = new (this.client.getRepresentor(contentType))(\n this.uri,\n contentType,\n body\n );\n\n if (!this.contentType) {\n this.contentType = contentType;\n }\n\n // Extracting HTTP Link header.\n const httpLinkHeader = response.headers.get('Link');\n if (httpLinkHeader) {\n\n for (const httpLink of LinkHeader.parse(httpLinkHeader).refs) {\n // Looping through individual links\n for (const rel of httpLink.rel.split(' ')) {\n // Looping through space separated rel values.\n this.repr.links.push(\n new Link({\n rel: rel,\n context: this.uri,\n href: httpLink.uri\n })\n );\n }\n }\n\n }\n\n // Parsing and storing embedded uris\n for (const uri of Object.keys(this.repr.embedded)) {\n const subResource = this.go(uri);\n subResource.repr = new (this.client.getRepresentor(contentType))(\n uri,\n contentType,\n this.repr.embedded[uri]\n );\n }\n\n return this.repr.body;\n\n }\n\n /**\n * Returns the links for this resource, as a promise.\n *\n * The rel argument is optional. If it's given, we will only return links\n * from that relationship type.\n */\n async links(rel?: string): Promise<Link[]> {\n\n const r = await this.representation();\n\n // After we got a representation, it no longer makes sense to remember\n // the rels we want to add to Prefer-Push.\n this.preferPushRels = new Set();\n\n if (!rel) { return r.links; }\n\n return r.links.filter( item => item.rel === rel );\n\n }\n\n /**\n * Follows a relationship, based on its reltype. For example, this might be\n * 'alternate', 'item', 'edit' or a custom url-based one.\n *\n * This function can also follow templated uris. You can specify uri\n * variables in the optional variables argument.\n */\n follow(rel: string, variables?: object): FollowablePromise {\n\n this.preferPushRels.add(rel);\n\n return new FollowablePromise(async (res: any, rej: any) => {\n\n try {\n const links = await this.links(rel);\n\n let href;\n if (links.length === 0) {\n throw new Error('Relation with type ' + rel + ' not found on resource ' + this.uri);\n }\n if (links[0].templated && variables) {\n href = links[0].expand(variables);\n } else {\n href = links[0].resolve();\n }\n\n const resource = this.go(href);\n if (links[0].type) {\n resource.contentType = links[0].type;\n }\n\n res(resource);\n\n } catch (reason) {\n rej(reason);\n }\n\n });\n\n }\n\n /**\n * Follows a relationship based on its reltype. This function returns a\n * Promise that resolves to an array of Resource objects.\n *\n * If no resources were found, the array will be empty.\n */\n async followAll(rel: string): Promise<Resource[]> {\n\n this.preferPushRels.add(rel);\n const links = await this.links(rel);\n\n return links.map((link: Link) => {\n const resource = this.go(link.resolve());\n if (link.type) {\n resource.contentType = link.type;\n }\n return resource;\n });\n\n }\n\n /**\n * Resolves a new resource based on a relative uri.\n *\n * Use this function to manually get a Resource object via a uri. The uri\n * will be resolved based on the uri of the current resource.\n *\n * This function doesn't do any HTTP requests.\n */\n go(uri: string): Resource {\n\n uri = resolve(this.uri, uri);\n return this.client.go(uri);\n\n }\n\n /**\n * Returns the representation for the object.\n * If it wasn't fetched yet, this function does the fetch as well.\n *\n * Usually you will want to use the `get()` method instead, unless you need\n * the full object.\n */\n async representation(): Promise<Representation> {\n\n if (!this.repr) {\n await this.refresh();\n }\n\n return <Representation> this.repr;\n\n }\n\n clearCache(): void {\n\n this.repr = null;\n\n }\n\n /**\n * Does an arbitrary HTTP request on the resource using the Fetch API.\n *\n * The method signature is the same as the MDN fetch object. However, it's\n * possible in this case to not specify a URI or specify a relative URI.\n *\n * When doing the actual request, any relative uri will be resolved to the\n * uri of the current resource.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/Request\n */\n fetch(input: Request|string|RequestInit, init?: RequestInit): Promise<Response> {\n\n let uri = null;\n let newInit: RequestInit = {};\n\n if (input === undefined) {\n // Nothing was provided, we're operating on the resource uri.\n uri = this.uri;\n } else if (typeof input === 'string') {\n // If it's a string, it might be relative uri so we're resolving it\n // first.\n uri = resolve(this.uri, input);\n\n } else if (input instanceof Request) {\n // We were passed a request object. We need to extract all its\n // information into the init object.\n uri = resolve(this.uri, (<Request> input).url);\n\n newInit.method = input.method;\n newInit.headers = new Headers(input.headers);\n // @ts-ignore: Possibly an error due to https://github.com/Microsoft/TypeScript/issues/15199\n newInit.body = input.body;\n newInit.mode = input.mode;\n newInit.credentials = input.credentials;\n newInit.cache = input.cache;\n newInit.redirect = input.redirect;\n newInit.referrer = input.referrer;\n newInit.integrity = input.integrity;\n\n } else if (input instanceof Object) {\n // if it was a regular 'object', but not a Request, we're assuming the\n // method was called with the init object as it's first parameter. This\n // is not allowed in the default Fetch API, but we do allow it because\n // in the resource, specifying the uri is optional.\n uri = this.uri;\n newInit = <RequestInit> input;\n } else {\n throw new TypeError('When specified, input must be a string, Request object or a key-value object');\n }\n\n // if the 'init' argument is specified, we're using it to override things\n // in newInit.\n if (init) {\n\n for (const key of Object.keys(init)) {\n if (key === 'headers') {\n // special case.\n continue;\n }\n (<any> newInit)[key] = (<any> init)[key];\n }\n newInit.headers = mergeHeaders([\n newInit.headers,\n init.headers\n ]);\n }\n\n // @ts-ignore cross-fetch definitions are broken. See https://github.com/lquixada/cross-fetch/pull/19\n const request = new Request(uri, newInit);\n\n return this.client.fetch(request);\n\n }\n\n /**\n * Does a HTTP request and throws an exception if the server emitted\n * a HTTP error.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/Request\n */\n async fetchAndThrow(input: Request|string|RequestInit, init?: RequestInit): Promise<Response> {\n\n const response = await this.fetch(input, init);\n\n if (response.ok) {\n return response;\n } else {\n throw await problemFactory(response);\n }\n\n }\n\n}\n","import OAuth2 from 'fetch-mw-oauth2';\nimport { AuthOptions, KettingInit } from '../types';\nimport * as base64 from './base64';\nimport './fetch-polyfill';\nimport { parse } from './url';\n\ntype DomainOptions = {\n fetchInit: RequestInit,\n auth: AuthOptions,\n authBucket: string,\n};\n\ntype beforeRequestCallback = (request: Request) => void;\n\n/**\n * This class is primarily responsible for calling fetch().\n *\n * It's main purpose besides that is to add authentication headers, and\n * any defaults that might have been set.\n */\nexport default class FetchHelper {\n\n private options: KettingInit;\n private oAuth2Buckets: Map<string, OAuth2>;\n private innerFetch: typeof fetch;\n private onBeforeRequest: beforeRequestCallback | null;\n\n constructor(options: KettingInit, onBeforeRequest: beforeRequestCallback | null = null) {\n this.options = options;\n this.oAuth2Buckets = new Map();\n this.innerFetch = fetch.bind(global);\n this.onBeforeRequest = onBeforeRequest;\n }\n\n fetch(requestInfo: RequestInfo, requestInit: RequestInit): Promise<Response> {\n\n const domainOptions = this.getDomainOptions(\n typeof requestInfo === 'string' ?\n requestInfo :\n requestInfo.url\n );\n\n const init = mergeInit([\n this.options.fetchInit,\n domainOptions.fetchInit,\n requestInit,\n {\n headers: requestInfo instanceof Request ? requestInfo.headers : {},\n },\n ]);\n\n const request = new Request(\n requestInfo,\n init\n );\n\n if (!request.headers.has('User-Agent')) {\n request.headers.set('User-Agent', 'Ketting/' + require('../../package.json').version);\n }\n\n return this.fetchAuth(request);\n\n }\n\n getDomainOptions(uri: string): DomainOptions {\n\n if (!this.options.match) {\n return {\n fetchInit: this.options.fetchInit,\n auth: this.options.auth,\n authBucket: '*',\n };\n }\n\n const { host } = parse(uri);\n for (const [matchStr, options] of Object.entries(this.options.match)) {\n\n const matchSplit = matchStr.split('*');\n const matchRegex = matchSplit.map(\n part =>\n part.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n ).join('(.*)');\n\n if (new RegExp('^' + matchRegex + '$').test(host)) {\n\n return {\n fetchInit: options.fetchInit,\n auth: options.auth || this.options.auth,\n authBucket: matchStr\n };\n }\n\n }\n return {\n fetchInit: this.options.fetchInit,\n auth: this.options.auth,\n authBucket: '*',\n };\n\n }\n\n /**\n * This method executes the actual fetch() function, but not before adding\n * authentication headers.\n */\n private fetchAuth(request: Request): Promise<Response> {\n\n const options = this.getDomainOptions(request.url);\n const authOptions = options.auth;\n const authBucket = options.authBucket;\n\n if (!authOptions) {\n return this.doFetch(request);\n }\n\n switch (authOptions.type) {\n case 'basic' :\n request.headers.set('Authorization', 'Basic ' + base64.encode(authOptions.userName + ':' + authOptions.password));\n return this.doFetch(request);\n case 'bearer' :\n request.headers.set('Authorization', 'Bearer ' + authOptions.token);\n return this.doFetch(request);\n case 'oauth2' :\n if (!this.oAuth2Buckets.has(authBucket)) {\n this.oAuth2Buckets.set(\n authBucket,\n new OAuth2(authOptions)\n );\n }\n if (this.onBeforeRequest) { this.onBeforeRequest(request); }\n return this.oAuth2Buckets.get(authBucket).fetch(request);\n }\n\n\n }\n\n /**\n * This function is the last mile before the actual fetch request is ran\n */\n private doFetch(request: Request): Promise<Response> {\n\n if (this.onBeforeRequest) {\n this.onBeforeRequest(request);\n }\n return this.innerFetch(request);\n\n }\n\n\n}\n\ntype HeaderSet = any;\n\n\n/**\n * 'init' refers to the init argument as passed to Request and Fetch objects.\n *\n * This function takes one or more of those init objects, and merges them.\n * Later properties override earlier ones.\n */\nfunction mergeInit(inits: RequestInit[]) {\n\n const newHeaders = mergeHeaders(\n inits.map( init => init ? init.headers : null )\n );\n\n const newInit = Object.assign({}, ...inits);\n newInit.headers = newHeaders;\n\n return newInit;\n\n}\n\n/**\n * Merges sets of HTTP headers.\n *\n * Each item in the array is a key->value object, a Fetch Headers object\n * or falsey.\n *\n * Any headers that appear more than once get replaced. The last occurence\n * wins.\n */\nexport function mergeHeaders(headerSets: HeaderSet[]): Headers {\n\n const result = new Headers();\n for (const headerSet of headerSets) {\n\n if (headerSet instanceof Headers) {\n for (const key of headerSet.keys()) {\n result.set(key, <string> headerSet.get(key));\n }\n } else if (headerSet) {\n // not falsey, must be a key->value object.\n for (const index of Object.keys(headerSet)) {\n result.set(index, headerSet[index]);\n }\n }\n }\n\n return result;\n\n}\n\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * An error class for any error the server emits.\n *\n * The 'code' property will have the oauth2 error type,\n * such as:\n * - invalid_request\n * - invalid_client\n * - invalid_grant\n * - unauthorized_client\n * - unsupported_grant_type\n * - invalid_scope\n */\nclass OAuthError extends Error {\n constructor(message, oauth2Code, httpCode) {\n super(message);\n this.oauth2Code = oauth2Code;\n this.httpCode = httpCode;\n }\n}\nexports.default = OAuthError;\n//# sourceMappingURL=error.js.map","export { default as Ketting, default } from './ketting';\nexport { default as Resource } from './resource';\n\n","import FollowablePromise from './followable-promise';\nimport Representor from './representor/base';\nimport HalRepresentor from './representor/hal';\nimport HtmlRepresentor from './representor/html';\nimport JsonApiRepresentor from './representor/jsonapi';\nimport Resource from './resource';\nimport { ContentType, KettingInit } from './types';\nimport FetchHelper from './utils/fetch-helper';\nimport './utils/fetch-polyfill';\nimport { resolve } from './utils/url';\n\n/**\n * The main Ketting client object.\n */\nexport default class Ketting {\n\n /**\n * The url from which all discovery starts.\n */\n bookMark: string;\n\n /**\n * Here we store all the resources that were ever requested. This will\n * ensure that if the same resource is requested twice, the same object is\n * returned.\n */\n resourceCache: { [url: string]: Resource };\n\n /**\n * Content-Type settings and mappings.\n *\n * See the constructor for an example of the structure.\n */\n contentTypes: ContentType[];\n\n /**\n * The helper class that calls fetch() for us\n */\n private fetchHelper: FetchHelper;\n\n constructor(bookMark: string, options?: KettingInit) {\n\n if (typeof options === 'undefined') {\n options = {};\n }\n\n this.resourceCache = {};\n\n this.contentTypes = [\n {\n mime: 'application/hal+json',\n representor: 'hal',\n q: '1.0',\n },\n {\n mime: 'application/vnd.api+json',\n representor: 'jsonapi',\n q: '0.9',\n },\n {\n mime: 'application/json',\n representor: 'hal',\n q: '0.8',\n },\n {\n mime: 'text/html',\n representor: 'html',\n q: '0.7',\n }\n ];\n\n this.bookMark = bookMark;\n this.fetchHelper = new FetchHelper(options, this.beforeRequest.bind(this));\n\n }\n\n /**\n * This function is a shortcut for getResource().follow(x);\n */\n follow(rel: string, variables?: object): FollowablePromise {\n\n return this.getResource().follow(rel, variables);\n\n }\n\n /**\n * Returns a resource by its uri.\n *\n * This function doesn't do any HTTP requests. The uri is optional. If it's\n * not specified, it will return the bookmark resource.\n *\n * If a relative uri is passed, it will be resolved based on the bookmark\n * uri.\n */\n go(uri?: string): Resource {\n\n if (typeof uri === 'undefined') {\n uri = '';\n }\n uri = resolve(this.bookMark, uri);\n\n if (!this.resourceCache[uri]) {\n this.resourceCache[uri] = new Resource(this, uri);\n }\n\n return this.resourceCache[uri];\n\n }\n\n /**\n * Returns a resource by its uri.\n *\n * This function doesn't do any HTTP requests. The uri is optional. If it's\n * not specified, it will return the bookmark resource.\n */\n getResource(uri?: string): Resource {\n\n return this.go(uri);\n\n }\n\n /**\n * This function does an arbitrary request using the fetch API.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch}\n */\n fetch(input: string|Request, init?: RequestInit): Promise<Response> {\n\n return this.fetchHelper.fetch(\n input,\n init\n );\n\n }\n\n /**\n * This function returns a representor constructor for a mime type.\n *\n * For example, given text/html, this function might return the constructor\n * stored in representor/html.\n */\n getRepresentor(contentType: string): typeof Representor {\n\n if (contentType.indexOf(';') !== -1) {\n contentType = contentType.split(';')[0];\n }\n contentType = contentType.trim();\n const result = this.contentTypes.find(item => {\n return item.mime === contentType;\n });\n\n if (!result) {\n throw new Error('Could not find a representor for contentType: ' + contentType);\n }\n\n switch (result.representor) {\n case 'html' :\n return HtmlRepresentor;\n case 'hal' :\n return HalRepresentor;\n case 'jsonapi' :\n return JsonApiRepresentor;\n default :\n throw new Error('Unknown representor: ' + result.representor);\n\n }\n\n }\n\n\n /**\n * Generates an accept header string, based on registered Resource Types.\n */\n getAcceptHeader(): string {\n\n return this.contentTypes\n .map( contentType => {\n let item = contentType.mime;\n if (contentType.q) { item += ';q=' + contentType.q; }\n return item;\n } )\n .join(', ');\n\n }\n\n beforeRequest(request: Request): void {\n\n const safeMethods = ['GET', 'HEAD', 'OPTIONS', 'PRI', 'PROPFIND', 'REPORT', 'SEARCH', 'TRACE'];\n if (safeMethods.includes(request.method)) {\n return;\n }\n\n if (request.url in this.resourceCache) {\n // Clear cache\n this.resourceCache[request.url].clearCache();\n }\n }\n\n}\n","import Link from '../link';\nimport { resolve } from '../utils/url';\nimport Representation from './base';\n\n/**\n * The Representation class is basically a 'body' of a request\n * or response.\n *\n * This class is for HAL JSON responses.\n */\nexport default class Hal extends Representation {\n\n body: { [s: string]: any };\n\n constructor(uri: string, contentType: string, body: any) {\n\n super(uri, contentType, body);\n\n if (typeof body === 'string') {\n this.body = JSON.parse(body);\n } else {\n this.body = body;\n }\n\n if (typeof this.body._links !== 'undefined') {\n parseHalLinks(this);\n }\n if (typeof this.body._embedded !== 'undefined') {\n parseHalEmbedded(this);\n }\n\n delete this.body._links;\n delete this.body._embedded;\n\n }\n\n}\n\n/**\n * Parse the Hal _links object and populate the 'links' property.\n */\nconst parseHalLinks = (representation: Hal): void => {\n\n for (const relType of Object.keys((<any> representation.body)._links)) {\n\n let links = (<any> representation.body)._links[relType];\n if (!Array.isArray(links)) {\n links = [links];\n }\n parseHalLink(representation, relType, links);\n\n }\n\n};\n\ntype HalLink = {\n href: string,\n name?: string,\n title: string,\n templated?: boolean,\n type?: string\n};\n\n/**\n * Parses a single HAL link from a _links object, or a list of links.\n */\nconst parseHalLink = (representation: Hal, rel: string, links: HalLink[]): void => {\n\n for (const link of links) {\n representation.links.push(\n new Link({\n rel: rel,\n context: representation.uri,\n href: link.href,\n title: link.title,\n type: link.type,\n templated: link.templated,\n name: link.name\n })\n );\n }\n\n};\n\n/**\n * Parse the HAL _embedded object. Right now we're just grabbing the\n * information from _embedded and turn it into links.\n */\nconst parseHalEmbedded = (representation: Hal): void => {\n\n for (const relType of Object.keys((<any> representation).body._embedded)) {\n\n let embedded = (<any> representation).body._embedded[relType];\n if (!Array.isArray(embedded)) {\n embedded = [embedded];\n }\n for (const embeddedItem of embedded) {\n\n const uri = resolve(\n representation.uri,\n embeddedItem._links.self.href\n );\n\n // Only adding a link to the representation if it didn't already exist.\n if (!representation.links.find( item => {\n return item.rel === relType && embeddedItem._links.self.href === item.href;\n })) {\n representation.links.push(\n new Link({\n rel: relType,\n context: representation.uri,\n href: embeddedItem._links.self.href\n })\n );\n }\n\n representation.embedded[uri] = embeddedItem;\n\n }\n }\n};\n","module.exports = (function(){\n /*\n * Generated by PEG.js 0.7.0.\n *\n * http://pegjs.majda.cz/\n */\n \n function quote(s) {\n /*\n * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a\n * string literal except for the closing quote character, backslash,\n * carriage return, line separator, paragraph separator, and line feed.\n * Any character may appear in the form of an escape sequence.\n *\n * For portability, we also escape escape all control and non-ASCII\n * characters. Note that \"\\0\" and \"\\v\" escape sequences are not used\n * because JSHint does not like the first and IE the second.\n */\n return '\"' + s\n .replace(/\\\\/g, '\\\\\\\\') // backslash\n .replace(/\"/g, '\\\\\"') // closing quote character\n .replace(/\\x08/g, '\\\\b') // backspace\n .replace(/\\t/g, '\\\\t') // horizontal tab\n .replace(/\\n/g, '\\\\n') // line feed\n .replace(/\\f/g, '\\\\f') // form feed\n .replace(/\\r/g, '\\\\r') // carriage return\n .replace(/[\\x00-\\x07\\x0B\\x0E-\\x1F\\x80-\\uFFFF]/g, escape)\n + '\"';\n }\n \n var result = {\n /*\n * Parses the input with a generated parser. If the parsing is successfull,\n * returns a value explicitly or implicitly specified by the grammar from\n * which the parser was generated (see |PEG.buildParser|). If the parsing is\n * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.\n */\n parse: function(input, startRule) {\n var parseFunctions = {\n \"uriTemplate\": parse_uriTemplate,\n \"expression\": parse_expression,\n \"op\": parse_op,\n \"pathExpression\": parse_pathExpression,\n \"paramList\": parse_paramList,\n \"param\": parse_param,\n \"cut\": parse_cut,\n \"listMarker\": parse_listMarker,\n \"substr\": parse_substr,\n \"nonexpression\": parse_nonexpression,\n \"extension\": parse_extension\n };\n \n if (startRule !== undefined) {\n if (parseFunctions[startRule] === undefined) {\n throw new Error(\"Invalid rule name: \" + quote(startRule) + \".\");\n }\n } else {\n startRule = \"uriTemplate\";\n }\n \n var pos = 0;\n var reportFailures = 0;\n var rightmostFailuresPos = 0;\n var rightmostFailuresExpected = [];\n \n function padLeft(input, padding, length) {\n var result = input;\n \n var padLength = length - input.length;\n for (var i = 0; i < padLength; i++) {\n result = padding + result;\n }\n \n return result;\n }\n \n function escape(ch) {\n var charCode = ch.charCodeAt(0);\n var escapeChar;\n var length;\n \n if (charCode <= 0xFF) {\n escapeChar = 'x';\n length = 2;\n } else {\n escapeChar = 'u';\n length = 4;\n }\n \n return '\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);\n }\n \n function matchFailed(failure) {\n if (pos < rightmostFailuresPos) {\n return;\n }\n \n if (pos > rightmostFailuresPos) {\n rightmostFailuresPos = pos;\n rightmostFailuresExpected = [];\n }\n \n rightmostFailuresExpected.push(failure);\n }\n \n function parse_uriTemplate() {\n var result0, result1;\n var pos0;\n \n pos0 = pos;\n result0 = [];\n result1 = parse_nonexpression();\n if (result1 === null) {\n result1 = parse_expression();\n }\n while (result1 !== null) {\n result0.push(result1);\n result1 = parse_nonexpression();\n if (result1 === null) {\n result1 = parse_expression();\n }\n }\n if (result0 !== null) {\n result0 = (function(offset, pieces) { return new Template(pieces) })(pos0, result0);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_expression() {\n var result0, result1, result2, result3;\n var pos0, pos1;\n \n pos0 = pos;\n pos1 = pos;\n if (input.charCodeAt(pos) === 123) {\n result0 = \"{\";\n pos++;\n } else {\n result0 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\"{\\\"\");\n }\n }\n if (result0 !== null) {\n result1 = parse_op();\n if (result1 !== null) {\n result2 = parse_paramList();\n if (result2 !== null) {\n if (input.charCodeAt(pos) === 125) {\n result3 = \"}\";\n pos++;\n } else {\n result3 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\"}\\\"\");\n }\n }\n if (result3 !== null) {\n result0 = [result0, result1, result2, result3];\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n if (result0 !== null) {\n result0 = (function(offset, op, params) { return expression(op, params) })(pos0, result0[1], result0[2]);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_op() {\n var result0;\n \n if (/^[\\/;:.?&+#]/.test(input.charAt(pos))) {\n result0 = input.charAt(pos);\n pos++;\n } else {\n result0 = null;\n if (reportFailures === 0) {\n matchFailed(\"[\\\\/;:.?&+#]\");\n }\n }\n if (result0 === null) {\n result0 = \"\";\n }\n return result0;\n }\n \n function parse_pathExpression() {\n var result0;\n \n if (input.substr(pos, 2) === \"{/\") {\n result0 = \"{/\";\n pos += 2;\n } else {\n result0 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\"{/\\\"\");\n }\n }\n return result0;\n }\n \n function parse_paramList() {\n var result0, result1, result2, result3;\n var pos0, pos1, pos2, pos3;\n \n pos0 = pos;\n pos1 = pos;\n result0 = parse_param();\n if (result0 !== null) {\n result1 = [];\n pos2 = pos;\n pos3 = pos;\n if (input.charCodeAt(pos) === 44) {\n result2 = \",\";\n pos++;\n } else {\n result2 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\",\\\"\");\n }\n }\n if (result2 !== null) {\n result3 = parse_param();\n if (result3 !== null) {\n result2 = [result2, result3];\n } else {\n result2 = null;\n pos = pos3;\n }\n } else {\n result2 = null;\n pos = pos3;\n }\n if (result2 !== null) {\n result2 = (function(offset, p) { return p; })(pos2, result2[1]);\n }\n if (result2 === null) {\n pos = pos2;\n }\n while (result2 !== null) {\n result1.push(result2);\n pos2 = pos;\n pos3 = pos;\n if (input.charCodeAt(pos) === 44) {\n result2 = \",\";\n pos++;\n } else {\n result2 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\",\\\"\");\n }\n }\n if (result2 !== null) {\n result3 = parse_param();\n if (result3 !== null) {\n result2 = [result2, result3];\n } else {\n result2 = null;\n pos = pos3;\n }\n } else {\n result2 = null;\n pos = pos3;\n }\n if (result2 !== null) {\n result2 = (function(offset, p) { return p; })(pos2, result2[1]);\n }\n if (result2 === null) {\n pos = pos2;\n }\n }\n if (result1 !== null) {\n result0 = [result0, result1];\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n if (result0 !== null) {\n result0 = (function(offset, hd, rst) { rst.unshift(hd); return rst; })(pos0, result0[0], result0[1]);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_param() {\n var result0, result1, result2;\n var pos0, pos1;\n \n pos0 = pos;\n pos1 = pos;\n result0 = [];\n if (/^[a-zA-Z0-9_.%]/.test(input.charAt(pos))) {\n result1 = input.charAt(pos);\n pos++;\n } else {\n result1 = null;\n if (reportFailures === 0) {\n matchFailed(\"[a-zA-Z0-9_.%]\");\n }\n }\n while (result1 !== null) {\n result0.push(result1);\n if (/^[a-zA-Z0-9_.%]/.test(input.charAt(pos))) {\n result1 = input.charAt(pos);\n pos++;\n } else {\n result1 = null;\n if (reportFailures === 0) {\n matchFailed(\"[a-zA-Z0-9_.%]\");\n }\n }\n }\n if (result0 !== null) {\n result1 = parse_cut();\n if (result1 === null) {\n result1 = parse_listMarker();\n }\n result1 = result1 !== null ? result1 : \"\";\n if (result1 !== null) {\n result2 = parse_extension();\n result2 = result2 !== null ? result2 : \"\";\n if (result2 !== null) {\n result0 = [result0, result1, result2];\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n if (result0 !== null) {\n result0 = (function(offset, chars, clm, e) { clm = clm || {};\n return {\n name: chars.join(''),\n explode: clm.listMarker,\n cut: clm.cut,\n extended: e\n } })(pos0, result0[0], result0[1], result0[2]);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_cut() {\n var result0;\n var pos0;\n \n pos0 = pos;\n result0 = parse_substr();\n if (result0 !== null) {\n result0 = (function(offset, cut) { return {cut: cut}; })(pos0, result0);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_listMarker() {\n var result0;\n var pos0;\n \n pos0 = pos;\n if (input.charCodeAt(pos) === 42) {\n result0 = \"*\";\n pos++;\n } else {\n result0 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\"*\\\"\");\n }\n }\n if (result0 !== null) {\n result0 = (function(offset, listMarker) { return {listMarker: listMarker}; })(pos0, result0);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_substr() {\n var result0, result1, result2;\n var pos0, pos1;\n \n pos0 = pos;\n pos1 = pos;\n if (input.charCodeAt(pos) === 58) {\n result0 = \":\";\n pos++;\n } else {\n result0 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\":\\\"\");\n }\n }\n if (result0 !== null) {\n if (/^[0-9]/.test(input.charAt(pos))) {\n result2 = input.charAt(pos);\n pos++;\n } else {\n result2 = null;\n if (reportFailures === 0) {\n matchFailed(\"[0-9]\");\n }\n }\n if (result2 !== null) {\n result1 = [];\n while (result2 !== null) {\n result1.push(result2);\n if (/^[0-9]/.test(input.charAt(pos))) {\n result2 = input.charAt(pos);\n pos++;\n } else {\n result2 = null;\n if (reportFailures === 0) {\n matchFailed(\"[0-9]\");\n }\n }\n }\n } else {\n result1 = null;\n }\n if (result1 !== null) {\n result0 = [result0, result1];\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n if (result0 !== null) {\n result0 = (function(offset, digits) { return parseInt(digits.join('')) })(pos0, result0[1]);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_nonexpression() {\n var result0, result1;\n var pos0;\n \n pos0 = pos;\n if (/^[^{]/.test(input.charAt(pos))) {\n result1 = input.charAt(pos);\n pos++;\n } else {\n result1 = null;\n if (reportFailures === 0) {\n matchFailed(\"[^{]\");\n }\n }\n if (result1 !== null) {\n result0 = [];\n while (result1 !== null) {\n result0.push(result1);\n if (/^[^{]/.test(input.charAt(pos))) {\n result1 = input.charAt(pos);\n pos++;\n } else {\n result1 = null;\n if (reportFailures === 0) {\n matchFailed(\"[^{]\");\n }\n }\n }\n } else {\n result0 = null;\n }\n if (result0 !== null) {\n result0 = (function(offset, chars) { return chars.join(''); })(pos0, result0);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n function parse_extension() {\n var result0, result1, result2;\n var pos0, pos1;\n \n pos0 = pos;\n pos1 = pos;\n if (input.charCodeAt(pos) === 40) {\n result0 = \"(\";\n pos++;\n } else {\n result0 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\"(\\\"\");\n }\n }\n if (result0 !== null) {\n if (/^[^)]/.test(input.charAt(pos))) {\n result2 = input.charAt(pos);\n pos++;\n } else {\n result2 = null;\n if (reportFailures === 0) {\n matchFailed(\"[^)]\");\n }\n }\n if (result2 !== null) {\n result1 = [];\n while (result2 !== null) {\n result1.push(result2);\n if (/^[^)]/.test(input.charAt(pos))) {\n result2 = input.charAt(pos);\n pos++;\n } else {\n result2 = null;\n if (reportFailures === 0) {\n matchFailed(\"[^)]\");\n }\n }\n }\n } else {\n result1 = null;\n }\n if (result1 !== null) {\n if (input.charCodeAt(pos) === 41) {\n result2 = \")\";\n pos++;\n } else {\n result2 = null;\n if (reportFailures === 0) {\n matchFailed(\"\\\")\\\"\");\n }\n }\n if (result2 !== null) {\n result0 = [result0, result1, result2];\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n } else {\n result0 = null;\n pos = pos1;\n }\n if (result0 !== null) {\n result0 = (function(offset, chars) { return chars.join('') })(pos0, result0[1]);\n }\n if (result0 === null) {\n pos = pos0;\n }\n return result0;\n }\n \n \n function cleanupExpected(expected) {\n expected.sort();\n \n var lastExpected = null;\n var cleanExpected = [];\n for (var i = 0; i < expected.length; i++) {\n if (expected[i] !== lastExpected) {\n cleanExpected.push(expected[i]);\n lastExpected = expected[i];\n }\n }\n return cleanExpected;\n }\n \n function computeErrorPosition() {\n /*\n * The first idea was to use |String.split| to break the input up to the\n * error position along newlines and derive the line and column from\n * there. However IE's |split| implementation is so broken that it was\n * enough to prevent it.\n */\n \n var line = 1;\n var column = 1;\n var seenCR = false;\n \n for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {\n var ch = input.charAt(i);\n if (ch === \"\\n\") {\n if (!seenCR) { line++; }\n column = 1;\n seenCR = false;\n } else if (ch === \"\\r\" || ch === \"\\u2028\" || ch === \"\\u2029\") {\n line++;\n column = 1;\n seenCR = true;\n } else {\n column++;\n seenCR = false;\n }\n }\n \n return { line: line, column: column };\n }\n \n \n var cls = require('./lib/classes')\n var Template = cls.Template\n var expression = cls.expression\n \n \n var result = parseFunctions[startRule]();\n \n /*\n * The parser is now in one of the following three states:\n *\n * 1. The parser successfully parsed the whole input.\n *\n * - |result !== null|\n * - |pos === input.length|\n * - |rightmostFailuresExpected| may or may not contain something\n *\n * 2. The parser successfully parsed only a part of the input.\n *\n * - |result !== null|\n * - |pos < input.length|\n * - |rightmostFailuresExpected| may or may not contain something\n *\n * 3. The parser did not successfully parse any part of the input.\n *\n * - |result === null|\n * - |pos === 0|\n * - |rightmostFailuresExpected| contains at least one failure\n *\n * All code following this comment (including called functions) must\n * handle these states.\n */\n if (result === null || pos !== input.length) {\n var offset = Math.max(pos, rightmostFailuresPos);\n var found = offset < input.length ? input.charAt(offset) : null;\n var errorPosition = computeErrorPosition();\n \n throw new this.SyntaxError(\n cleanupExpected(rightmostFailuresExpected),\n found,\n offset,\n errorPosition.line,\n errorPosition.column\n );\n }\n \n return result;\n },\n \n /* Returns the parser source code. */\n toSource: function() { return this._source; }\n };\n \n /* Thrown when a parser encounters a syntax error. */\n \n result.SyntaxError = function(expected, found, offset, line, column) {\n function buildMessage(expected, found) {\n var expectedHumanized, foundHumanized;\n \n switch (expected.length) {\n case 0:\n expectedHumanized = \"end of input\";\n break;\n case 1:\n expectedHumanized = expected[0];\n break;\n default:\n expectedHumanized = expected.slice(0, expected.length - 1).join(\", \")\n + \" or \"\n + expected[expected.length - 1];\n }\n \n foundHumanized = found ? quote(found) : \"end of input\";\n \n return \"Expected \" + expectedHumanized + \" but \" + foundHumanized + \" found.\";\n }\n \n this.name = \"SyntaxError\";\n this.expected = expected;\n this.found = found;\n this.message = buildMessage(expected, found);\n this.offset = offset;\n this.line = line;\n this.column = column;\n };\n \n result.SyntaxError.prototype = Error.prototype;\n \n return result;\n})();\n","// Generated by CoffeeScript 1.6.3\n(function() {\n var FormContinuationExpression, FormStartExpression, FragmentExpression, LabelExpression, NamedExpression, PathParamExpression, PathSegmentExpression, ReservedExpression, SimpleExpression, Template, encoders, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7,\n __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },\n __hasProp = {}.hasOwnProperty,\n __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };\n\n encoders = require('./encoders');\n\n Template = Template = (function() {\n function Template(pieces) {\n /*\n :param pieces: An array of strings and expressions in the order they appear in the template.\n */\n\n var i,\n _this = this;\n this.expressions = [];\n this.prefix = 'string' === typeof pieces[0] ? pieces.shift() : '';\n i = 0;\n pieces.forEach(function(p) {\n switch (typeof p) {\n case 'object':\n return _this.expressions[i++] = p;\n case 'string':\n return _this.expressions[i - 1].suffix = p;\n }\n });\n }\n\n Template.prototype.expand = function(vars) {\n return this.prefix + this.expressions.map(function(expr) {\n return expr.expand(vars);\n }).join('');\n };\n\n Template.prototype.toString = function() {\n return this.prefix + this.expressions.join('');\n };\n\n Template.prototype.toJSON = function() {\n return this.toString();\n };\n\n return Template;\n\n })();\n\n SimpleExpression = (function() {\n var definedPairs;\n\n SimpleExpression.prototype.first = \"\";\n\n SimpleExpression.prototype.sep = \",\";\n\n SimpleExpression.prototype.named = false;\n\n SimpleExpression.prototype.empty = \"\";\n\n SimpleExpression.prototype.allow = \"U\";\n\n function SimpleExpression(params) {\n this.params = params;\n this.explodeObject = __bind(this.explodeObject, this);\n this.explodeArray = __bind(this.explodeArray, this);\n this._expandPair = __bind(this._expandPair, this);\n this.stringifySingle = __bind(this.stringifySingle, this);\n this.encode = __bind(this.encode, this);\n if (this.params == null) {\n this.params = [];\n }\n this.suffix = '';\n }\n\n SimpleExpression.prototype.encode = function(string) {\n /*\n Encode a string value for the URI\n */\n\n return encoders[this.allow](string);\n };\n\n SimpleExpression.prototype.stringifySingle = function(param, value) {\n /*\n Encode a single value as a string\n */\n\n var k, type, v;\n type = typeof value;\n if (type === 'string' || type === 'boolean' || type === 'number') {\n value = value.toString();\n return this.encode(value.substring(0, param.cut || value.length));\n } else if (Array.isArray(value)) {\n if (param.cut) {\n throw new Error(\"Prefixed Values do not support lists. Check \" + param.name);\n }\n return value.map(this.encode).join(',');\n } else {\n if (param.cut) {\n throw new Error(\"Prefixed Values do not support maps. Check \" + param.name);\n }\n return ((function() {\n var _results;\n _results = [];\n for (k in value) {\n v = value[k];\n _results.push([k, v].map(this.encode).join(','));\n }\n return _results;\n }).call(this)).join(',');\n }\n };\n\n SimpleExpression.prototype.expand = function(vars) {\n var defined, expanded,\n _this = this;\n defined = definedPairs(this.params, vars);\n expanded = defined.map(function(pair) {\n return _this._expandPair.apply(_this, pair);\n }).join(this.sep);\n if (expanded) {\n return this.first + expanded + this.suffix;\n } else {\n if (this.empty && defined.length) {\n return this.empty + this.suffix;\n } else {\n return this.suffix;\n }\n }\n };\n\n definedPairs = function(params, vars) {\n /*\n Return an array of [key, value] arrays where ``key`` is a parameter name\n from ``@params`` and ``value`` is the value from vars, when ``value`` is\n neither undefined nor an empty collection.\n */\n\n var _this = this;\n return params.map(function(p) {\n return [p, vars[p.name]];\n }).filter(function(pair) {\n var k, v, vv;\n v = pair[1];\n switch (typeof v) {\n case \"undefined\":\n return false;\n case \"object\":\n if (Array.isArray(v)) {\n v.length > 0;\n }\n for (k in v) {\n vv = v[k];\n if (vv) {\n return true;\n }\n }\n return false;\n default:\n return true;\n }\n });\n };\n\n SimpleExpression.prototype._expandPair = function(param, value) {\n /*\n Return the expanded string form of ``pair``.\n \n :param pair: A ``[param, value]`` tuple.\n */\n\n var name;\n name = param.name;\n if (param.explode) {\n if (Array.isArray(value)) {\n return this.explodeArray(param, value);\n } else if (typeof value === 'string') {\n return this.stringifySingle(param, value);\n } else {\n return this.explodeObject(value);\n }\n } else {\n return this.stringifySingle(param, value);\n }\n };\n\n SimpleExpression.prototype.explodeArray = function(param, array) {\n return array.map(this.encode).join(this.sep);\n };\n\n SimpleExpression.prototype.explodeObject = function(object) {\n var k, pairs, v, vv, _i, _len;\n pairs = [];\n for (k in object) {\n v = object[k];\n k = this.encode(k);\n if (Array.isArray(v)) {\n for (_i = 0, _len = v.length; _i < _len; _i++) {\n vv = v[_i];\n pairs.push([k, this.encode(vv)]);\n }\n } else {\n pairs.push([k, this.encode(v)]);\n }\n }\n return pairs.map(function(pair) {\n return pair.join('=');\n }).join(this.sep);\n };\n\n SimpleExpression.prototype.toString = function() {\n var params;\n params = this.params.map(function(p) {\n return p.name + p.explode;\n }).join(',');\n return \"{\" + this.first + params + \"}\" + this.suffix;\n };\n\n SimpleExpression.prototype.toJSON = function() {\n return this.toString();\n };\n\n return SimpleExpression;\n\n })();\n\n NamedExpression = (function(_super) {\n __extends(NamedExpression, _super);\n\n function NamedExpression() {\n this.explodeArray = __bind(this.explodeArray, this);\n this.stringifySingle = __bind(this.stringifySingle, this);\n _ref = NamedExpression.__super__.constructor.apply(this, arguments);\n return _ref;\n }\n\n /*\n A NamedExpression uses name=value expansions in most cases\n */\n\n\n NamedExpression.prototype.stringifySingle = function(param, value) {\n value = (value = NamedExpression.__super__.stringifySingle.apply(this, arguments)) ? \"=\" + value : this.empty;\n return \"\" + param.name + value;\n };\n\n NamedExpression.prototype.explodeArray = function(param, array) {\n var _this = this;\n return array.map(function(v) {\n return \"\" + param.name + \"=\" + (_this.encode(v));\n }).join(this.sep);\n };\n\n return NamedExpression;\n\n })(SimpleExpression);\n\n ReservedExpression = (function(_super) {\n __extends(ReservedExpression, _super);\n\n function ReservedExpression() {\n _ref1 = ReservedExpression.__super__.constructor.apply(this, arguments);\n return _ref1;\n }\n\n ReservedExpression.prototype.encode = function(string) {\n return encoders['U+R'](string);\n };\n\n ReservedExpression.prototype.toString = function() {\n return '{+' + (ReservedExpression.__super__.toString.apply(this, arguments)).substring(1);\n };\n\n return ReservedExpression;\n\n })(SimpleExpression);\n\n FragmentExpression = (function(_super) {\n __extends(FragmentExpression, _super);\n\n function FragmentExpression() {\n _ref2 = FragmentExpression.__super__.constructor.apply(this, arguments);\n return _ref2;\n }\n\n FragmentExpression.prototype.first = '#';\n\n FragmentExpression.prototype.empty = '#';\n\n FragmentExpression.prototype.encode = function(string) {\n return encoders['U+R'](string);\n };\n\n return FragmentExpression;\n\n })(SimpleExpression);\n\n LabelExpression = (function(_super) {\n __extends(LabelExpression, _super);\n\n function LabelExpression() {\n _ref3 = LabelExpression.__super__.constructor.apply(this, arguments);\n return _ref3;\n }\n\n LabelExpression.prototype.first = '.';\n\n LabelExpression.prototype.sep = '.';\n\n LabelExpression.prototype.empty = '.';\n\n return LabelExpression;\n\n })(SimpleExpression);\n\n PathSegmentExpression = (function(_super) {\n __extends(PathSegmentExpression, _super);\n\n function PathSegmentExpression() {\n _ref4 = PathSegmentExpression.__super__.constructor.apply(this, arguments);\n return _ref4;\n }\n\n PathSegmentExpression.prototype.first = '/';\n\n PathSegmentExpression.prototype.sep = '/';\n\n return PathSegmentExpression;\n\n })(SimpleExpression);\n\n PathParamExpression = (function(_super) {\n __extends(PathParamExpression, _super);\n\n function PathParamExpression() {\n _ref5 = PathParamExpression.__super__.constructor.apply(this, arguments);\n return _ref5;\n }\n\n PathParamExpression.prototype.first = ';';\n\n PathParamExpression.prototype.sep = ';';\n\n return PathParamExpression;\n\n })(NamedExpression);\n\n FormStartExpression = (function(_super) {\n __extends(FormStartExpression, _super);\n\n function FormStartExpression() {\n _ref6 = FormStartExpression.__super__.constructor.apply(this, arguments);\n return _ref6;\n }\n\n FormStartExpression.prototype.first = '?';\n\n FormStartExpression.prototype.sep = '&';\n\n FormStartExpression.prototype.empty = '=';\n\n return FormStartExpression;\n\n })(NamedExpression);\n\n FormContinuationExpression = (function(_super) {\n __extends(FormContinuationExpression, _super);\n\n function FormContinuationExpression() {\n _ref7 = FormContinuationExpression.__super__.constructor.apply(this, arguments);\n return _ref7;\n }\n\n FormContinuationExpression.prototype.first = '&';\n\n return FormContinuationExpression;\n\n })(FormStartExpression);\n\n module.exports = {\n Template: Template,\n SimpleExpression: SimpleExpression,\n NamedExpression: NamedExpression,\n ReservedExpression: ReservedExpression,\n FragmentExpression: FragmentExpression,\n LabelExpression: LabelExpression,\n PathSegmentExpression: PathSegmentExpression,\n PathParamExpression: PathParamExpression,\n FormStartExpression: FormStartExpression,\n FormContinuationExpression: FormContinuationExpression,\n expression: function(op, params) {\n var cls;\n cls = (function() {\n switch (op) {\n case '':\n return SimpleExpression;\n case '+':\n return ReservedExpression;\n case '#':\n return FragmentExpression;\n case '.':\n return LabelExpression;\n case '/':\n return PathSegmentExpression;\n case ';':\n return PathParamExpression;\n case '?':\n return FormStartExpression;\n case '&':\n return FormContinuationExpression;\n }\n })();\n return new cls(params);\n }\n };\n\n}).call(this);\n","// Generated by CoffeeScript 1.6.3\n(function() {\n var pctEncode;\n\n pctEncode = require('pct-encode');\n\n exports[\"U\"] = pctEncode(/[^\\w~.-]/g);\n\n exports[\"U+R\"] = pctEncode(/[^\\w.~:\\/\\?#\\[\\]@!\\$&'()*+,;=%-]|%(?!\\d\\d)/g);\n\n}).call(this);\n","module.exports = function pctEncode(regexp) {\n regexp = regexp || /\\W/g;\n return function encode(string) {\n string = String(string);\n return string.replace(regexp, function (m) {\n var c = m[0].charCodeAt(0)\n , encoded = [];\n if (c < 128) {\n encoded.push(c);\n } else if ((128 <= c && c < 2048)) {\n encoded.push((c >> 6) | 192);\n encoded.push((c & 63) | 128);\n } else {\n encoded.push((c >> 12) | 224);\n encoded.push(((c >> 6) & 63) | 128);\n encoded.push((c & 63) | 128);\n }\n return encoded.map(function (c) {\n return '%' + c.toString(16).toUpperCase();\n }).join('');\n })\n }\n}\n","import Link from '../link';\nimport Representation from './base';\n\n/**\n * The Representation class is basically a 'body' of a request\n * or response.\n *\n * This class is for HTML responses. The html.web.js version is the version\n * intended for browsers. The regular html.js is intended for node.js.\n */\nexport default class Html extends Representation {\n\n constructor(uri: string, contentType: string, body: string) {\n\n super(uri, contentType, body);\n\n const parser = new DOMParser();\n const doc = parser.parseFromString(body, 'text/html');\n\n linkFromTags(\n this,\n doc.getElementsByTagName('link')\n );\n\n linkFromTags(\n this,\n doc.getElementsByTagName('a')\n );\n\n }\n\n}\n\nfunction linkFromTags(htmlDoc: Html, elements: HTMLCollectionOf<HTMLElement>) {\n\n for (const node of elements) {\n\n const rels = node.getAttribute('rel');\n const href = node.getAttribute('href');\n const type = node.getAttribute('type') || undefined;\n\n if (!rels || !href) {\n continue;\n }\n\n for (const rel of rels.split(' ')) {\n\n const link = new Link({\n rel: rel,\n context: htmlDoc.uri,\n href: href,\n type: type\n });\n htmlDoc.links.push(link);\n\n }\n\n }\n\n}\n","import Link from '../link';\n// import { resolve } from '../utils/url';\nimport Representation from './base';\n\n/**\n * A JSON:API link can either be a string, or an object with at least a href\n * property.\n */\ntype JsonApiLink = string | { href: string };\n\n/**\n * This type is a full 'links' object, which might appear on the top level\n * or on resource objects.\n */\ntype JsonApiLinksObject = {\n self?: JsonApiLink,\n profile?: JsonApiLink\n [rel: string]: JsonApiLink | JsonApiLink[]\n};\n\n/**\n * This is a single JSON:API resource. Its type contains just the properties\n * we care about.\n */\ntype JsonApiResource = {\n type: string,\n id: string,\n links?: JsonApiLinksObject,\n};\n\n\n/**\n * This type represents a valid JSON:API response. We're only interested\n * in the links object at the moment, so everything else is (for now)\n * untyped.\n */\ntype JsonApiTopLevelObject = {\n links?: JsonApiLinksObject,\n data: JsonApiResource | JsonApiResource[] | null,\n [s: string]: any\n};\n\n/**\n * This class represents JSON:API responses.\n *\n * The Representor is responsible from extracting any links from the body,\n * so they can be followed.\n */\nexport default class JsonApi extends Representation {\n\n body: JsonApiTopLevelObject;\n\n constructor(uri: string, contentType: string, body: any) {\n\n super(uri, contentType, body);\n\n if (typeof body === 'string') {\n this.body = JSON.parse(body);\n } else {\n this.body = body;\n }\n\n this.links = [\n ...parseJsonApiLinks(uri, this.body),\n ...parseJsonApiCollection(uri, this.body)\n ];\n\n }\n\n}\n\n/**\n * This function takes a JSON:API object, and extracts the links property.\n */\nfunction parseJsonApiLinks(baseHref: string, body: JsonApiTopLevelObject): Link[] {\n\n const result: Link[] = [];\n\n if (body.links === undefined) {\n return result;\n }\n\n for (const [rel, linkValue] of Object.entries(body.links)) {\n\n if (Array.isArray(linkValue)) {\n result.push(...linkValue.map( link => parseJsonApiLink(baseHref, rel, link)));\n } else {\n result.push(parseJsonApiLink(baseHref, rel, linkValue));\n }\n\n }\n\n return result;\n\n}\n\n/**\n * Find collection members in JSON:API objects.\n *\n * A JSON:API top-level object might represent a collection that has 0 or more\n * members.\n *\n * Members of this collection should appear as an 'item' link to the parent.\n */\nfunction parseJsonApiCollection(baseHref: string, body: JsonApiTopLevelObject): Link[] {\n\n if (!Array.isArray(body.data)) {\n // Not a collection\n return [];\n }\n\n const result: Link[] = [];\n for (const member of body.data) {\n\n if ('self' in member.links) {\n\n const selfLink = parseJsonApiLink(baseHref, 'self', member.links.self);\n result.push(new Link({\n context: baseHref,\n href: selfLink.href,\n rel: 'item'\n }));\n\n }\n }\n\n return result;\n\n}\n\n/**\n * This function takes a single link value from a JSON:API link object, and\n * returns a object of type Link\n */\nfunction parseJsonApiLink(baseHref: string, rel: string, link: JsonApiLink): Link {\n\n return new Link({\n context: baseHref,\n rel,\n href: typeof link === 'string' ? link : link.href,\n });\n\n}\n","'use strict'\n\nvar COMPATIBLE_ENCODING_PATTERN = /^utf-?8|ascii|utf-?16-?le|ucs-?2|base-?64|latin-?1$/i\nvar WS_TRIM_PATTERN = /^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g\nvar WS_CHAR_PATTERN = /\\s|\\uFEFF|\\xA0/\nvar WS_FOLD_PATTERN = /\\r?\\n[\\x20\\x09]+/g\nvar DELIMITER_PATTERN = /[;,\"]/\nvar WS_DELIMITER_PATTERN = /[;,\"]|\\s/\n\nvar STATE = {\n IDLE: 1 << 0,\n URI: 1 << 1,\n ATTR: 1 << 2,\n}\n\nfunction trim( value ) {\n return value.replace( WS_TRIM_PATTERN, '' )\n}\n\nfunction hasWhitespace( value ) {\n return WS_CHAR_PATTERN.test( value )\n}\n\nfunction skipWhitespace( value, offset ) {\n while( hasWhitespace( value[offset] ) ) {\n offset++\n }\n return offset\n}\n\nfunction needsQuotes( value ) {\n return WS_DELIMITER_PATTERN.test( value )\n}\n\nclass Link {\n\n /**\n * Link\n * @constructor\n * @param {String} [value]\n * @returns {Link}\n */\n constructor( value ) {\n\n /** @type {Array} URI references */\n this.refs = []\n\n if( value ) {\n this.parse( value )\n }\n\n }\n\n /**\n * Get refs with given relation type\n * @param {String} value\n * @returns {Array<Object>}\n */\n rel( value ) {\n\n var links = []\n\n for( var i = 0; i < this.refs.length; i++ ) {\n if( this.refs[ i ].rel === value ) {\n links.push( this.refs[ i ] )\n }\n }\n\n return links\n\n }\n\n /**\n * Get refs where given attribute has a given value\n * @param {String} attr\n * @param {String} value\n * @returns {Array<Object>}\n */\n get( attr, value ) {\n\n attr = attr.toLowerCase()\n\n var links = []\n\n for( var i = 0; i < this.refs.length; i++ ) {\n if( this.refs[ i ][ attr ] === value ) {\n links.push( this.refs[ i ] )\n }\n }\n\n return links\n\n }\n\n set( link ) {\n this.refs.push( link )\n return this\n }\n\n has( attr, value ) {\n\n attr = attr.toLowerCase()\n\n for( var i = 0; i < this.refs.length; i++ ) {\n if( this.refs[ i ][ attr ] === value ) {\n return true\n }\n }\n\n return false\n\n }\n\n parse( value, offset ) {\n\n offset = offset || 0\n value = offset ? value.slice( offset ) : value\n\n // Trim & unfold folded lines\n value = trim( value ).replace( WS_FOLD_PATTERN, '' )\n\n var state = STATE.IDLE\n var length = value.length\n var offset = 0\n var ref = null\n\n while( offset < length ) {\n if( state === STATE.IDLE ) {\n if( hasWhitespace( value[offset] ) ) {\n offset++\n continue\n } else if( value[offset] === '<' ) {\n var end = value.indexOf( '>', offset )\n if( end === -1 ) throw new Error( 'Expected end of URI delimiter at offset ' + offset )\n ref = { uri: value.slice( offset + 1, end ) }\n this.refs.push( ref )\n offset = end\n state = STATE.URI\n } else {\n throw new Error( 'Unexpected character \"' + value[offset] + '\" at offset ' + offset )\n }\n offset++\n } else if( state === STATE.URI ) {\n if( hasWhitespace( value[offset] ) ) {\n offset++\n continue\n } else if( value[offset] === ';' ) {\n state = STATE.ATTR\n offset++\n } else if( value[offset] === ',' ) {\n state = STATE.IDLE\n offset++\n } else {\n throw new Error( 'Unexpected character \"' + value[offset] + '\" at offset ' + offset )\n }\n } else if( state === STATE.ATTR ) {\n if( value[offset] ===';' || hasWhitespace( value[offset] ) ) {\n offset++\n continue\n }\n var end = value.indexOf( '=', offset )\n if( end === -1 ) throw new Error( 'Expected attribute delimiter at offset ' + offset )\n var attr = trim( value.slice( offset, end ) ).toLowerCase()\n var attrValue = ''\n offset = end + 1\n offset = skipWhitespace( value, offset )\n if( value[offset] === '\"' ) {\n offset++\n while( offset < length ) {\n if( value[offset] === '\"' ) {\n offset++; break\n }\n if( value[offset] === '\\\\' ) {\n offset++\n }\n attrValue += value[offset]\n offset++\n }\n } else {\n var end = offset + 1\n while( !DELIMITER_PATTERN.test( value[end] ) && end < length ) {\n end++\n }\n attrValue = value.slice( offset, end )\n offset = end\n }\n if( ref[ attr ] && Link.isSingleOccurenceAttr( attr ) ) {\n // Ignore multiples of attributes which may only appear once\n } else if( attr[ attr.length - 1 ] === '*' ) {\n ref[ attr ] = Link.parseExtendedValue( attrValue )\n } else {\n attrValue = attr === 'rel' || attr === 'type' ?\n attrValue.toLowerCase() : attrValue\n if( ref[ attr ] != null ) {\n if( Array.isArray( ref[ attr ] ) ) {\n ref[ attr ].push( attrValue )\n } else {\n ref[ attr ] = [ ref[ attr ], attrValue ]\n }\n } else {\n ref[ attr ] = attrValue\n }\n }\n switch( value[offset] ) {\n case ',': state = STATE.IDLE; break\n case ';': state = STATE.ATTR; break\n }\n offset++\n } else {\n throw new Error( 'Unknown parser state \"' + state + '\"' )\n }\n }\n\n ref = null\n\n return this\n\n }\n\n toString() {\n\n var refs = []\n var link = ''\n var ref = null\n\n for( var i = 0; i < this.refs.length; i++ ) {\n ref = this.refs[i]\n link = Object.keys( this.refs[i] ).reduce( function( link, attr ) {\n if( attr === 'uri' ) return link\n return link + '; ' + Link.formatAttribute( attr, ref[ attr ] )\n }, '<' + ref.uri + '>' )\n refs.push( link )\n }\n\n return refs.join( ', ' )\n\n }\n\n}\n\n/**\n * Determines whether an encoding can be\n * natively handled with a `Buffer`\n * @param {String} value\n * @returns {Boolean}\n */\nLink.isCompatibleEncoding = function( value ) {\n return COMPATIBLE_ENCODING_PATTERN.test( value )\n}\n\nLink.parse = function( value, offset ) {\n return new Link().parse( value, offset )\n}\n\nLink.isSingleOccurenceAttr = function( attr ) {\n return attr === 'rel' || attr === 'type' || attr === 'media' ||\n attr === 'title' || attr === 'title*'\n}\n\nLink.isTokenAttr = function( attr ) {\n return attr === 'rel' || attr === 'type' || attr === 'anchor'\n}\n\nLink.escapeQuotes = function( value ) {\n return value.replace( /\"/g, '\\\\\"' )\n}\n\n/**\n * Parses an extended value and attempts to decode it\n * @internal\n * @param {String} value\n * @return {Object}\n */\nLink.parseExtendedValue = function( value ) {\n var parts = /([^']+)?(?:'([^']+)')?(.+)/.exec( value )\n return {\n language: parts[2].toLowerCase(),\n encoding: Link.isCompatibleEncoding( parts[1] ) ?\n null : parts[1].toLowerCase(),\n value: Link.isCompatibleEncoding( parts[1] ) ?\n decodeURIComponent( parts[3] ) : parts[3]\n }\n}\n\n/**\n * Format a given extended attribute and it's value\n * @param {String} attr\n * @param {Object} data\n * @return {String}\n */\nLink.formatExtendedAttribute = function( attr, data ) {\n\n var encoding = ( data.encoding || 'utf-8' ).toUpperCase()\n var language = data.language || 'en'\n\n var encodedValue = ''\n\n if( Buffer.isBuffer( data.value ) && Link.isCompatibleEncoding( encoding ) ) {\n encodedValue = data.value.toString( encoding )\n } else if( Buffer.isBuffer( data.value ) ) {\n encodedValue = data.value.toString( 'hex' )\n .replace( /[0-9a-f]{2}/gi, '%$1' )\n } else {\n encodedValue = encodeURIComponent( data.value )\n }\n\n return attr + '=' + encoding + '\\'' +\n language + '\\'' + encodedValue\n\n}\n\n/**\n * Format a given attribute and it's value\n * @param {String} attr\n * @param {String|Object} value\n * @return {String}\n */\nLink.formatAttribute = function( attr, value ) {\n\n if( Array.isArray( value ) ) {\n return value.map(( item ) => {\n return Link.formatAttribute( attr, item )\n }).join( '; ' )\n }\n\n if( attr[ attr.length - 1 ] === '*' || typeof value !== 'string' ) {\n return Link.formatExtendedAttribute( attr, value )\n }\n\n if( Link.isTokenAttr( attr ) ) {\n value = needsQuotes( value ) ?\n '\"' + Link.escapeQuotes( value ) + '\"' :\n Link.escapeQuotes( value )\n } else if( needsQuotes( value ) ) {\n value = encodeURIComponent( value )\n // We don't need to escape <SP> <,> <;> within quotes\n value = value\n .replace( /%20/g, ' ' )\n .replace( /%2C/g, ',' )\n .replace( /%3B/g, ';' )\n\n value = '\"' + value + '\"'\n }\n\n return attr + '=' + value\n\n}\n\nmodule.exports = Link\n","import Resource from './resource';\n\ntype Executor =\n (\n res: ((value: FollowablePromise) => void),\n rej: ((reason: any) => any)\n )\n => void;\n\n/**\n * The FollowablePromise is a Promise that adds the follow and followAll\n * functions.\n *\n * It's really just a thin wrapper around the promise. Note that we're not\n * extending the built-in Promise object, but proxy it as browsers don't allow\n * extending the Promise object.\n */\nexport default class FollowablePromise {\n\n realPromise: Promise<Resource>;\n\n constructor(executor: Executor ) {\n this.realPromise = new Promise(executor);\n }\n\n /**\n * The then function maps to a standard then function, as it appears on the\n * promise.\n */\n then(onResolve: (result: any) => Resource | Promise<Resource>, onReject?: (reason: any) => never): Promise<Resource> {\n return this.realPromise.then(onResolve, onReject);\n }\n\n /**\n * The catch function maps to a standard then function, as it appears on the\n * promise.\n */\n catch<T>(onReject: (reason: any) => Promise<T> | T): Promise<Resource | T> {\n return this.realPromise.catch(onReject);\n }\n\n /**\n * The follow function will wait for this promise to resolve, assume the\n * resolved value is a Ketting resource and then call 'follow' on it.\n *\n * The function returns a Promise that will resolve into the result of that\n * 'follow' function.\n *\n * In practice this means you can chain multiple 'follow' calls.\n */\n follow(rel: string, variables?: object): FollowablePromise {\n\n return new FollowablePromise((resolve: (value: FollowablePromise) => void, reject: (reason: any) => void) => {\n\n this.realPromise.then((resource: Resource) => {\n resolve(resource.follow(rel, variables));\n\n }).catch(err => {\n reject(err);\n });\n\n });\n\n }\n\n /**\n * The followAll function will wait for this promise to resolve, assume the\n * resolved value is a Ketting resource and then call 'followAll' on it.\n *\n * The function returns a Promise that will resolve into the result of that\n * 'followAll' function.\n *\n * In practice this means you can end a chain of 'follow' calls in the\n * 'followAll' call.\n *\n * It's really the same idea as the follow function, except that you can't\n * keep on chaining after the followAll, because it resolves in an array of\n * resources.\n */\n followAll(rel: string): Promise<Resource[]> {\n return this.realPromise.then((resource: Resource) => {\n return resource.followAll(rel);\n });\n }\n\n}\n","/**\n * HttpError extends the Error object, and is thrown wheenever servers emit\n * HTTP errors.\n *\n * It has a response property, allowing users to find out more about the\n * nature of the error.\n *\n * @constructor\n * @param {Response} response\n */\nexport class HttpError extends Error {\n\n response: Response;\n status: number;\n\n constructor(response: Response) {\n super('HTTP error ' + response.status);\n this.response = response;\n this.status = response.status;\n }\n\n}\n\n/**\n * Problem extends the HttpError object. If a server emits a HTTP error, and\n * the response body's content-type is application/problem+json.\n *\n * application/problem+json is defined in RFC7807 and provides a standardized\n * way to describe error conditions by a HTTP server.\n *\n * @constructor\n * @param {Response} response\n * @param {object} problemBody\n */\nexport class Problem extends HttpError {\n\n body: {\n title?: string\n };\n\n constructor(response: Response, problemBody: object) {\n super(response);\n this.body = problemBody;\n if (this.body.title) {\n this.message = 'HTTP Error ' + this.status + ': ' + this.body.title;\n }\n }\n\n}\n\n/**\n * This function creates problems, not unlike the the author of this file.\n *\n * It takes a Fetch Response object, and returns a HttpError. If the HTTP\n * response has a type of application/problem+json it will return a Problem\n * object.\n *\n * Because parsing the response might be asynchronous, the function returns\n * a Promise resolving in either object.\n */\nexport default async function problemFactory(response: Response): Promise<HttpError | Problem> {\n\n const contentType = response.headers.get('Content-Type');\n if (contentType && contentType.match(/^application\\/problem\\+json/i)) {\n const problemBody = await response.json();\n return new Problem(response, problemBody);\n } else {\n return new HttpError(response);\n }\n\n}\n\n","var g;\n\n// This works in non-strict mode\ng = (function() {\n\treturn this;\n})();\n\ntry {\n\t// This works if eval is allowed (see CSP)\n\tg = g || new Function(\"return this\")();\n} catch (e) {\n\t// This works if the window reference is available\n\tif (typeof window === \"object\") g = window;\n}\n\n// g can still be undefined, but nothing to do about it...\n// We return undefined, instead of nothing here, so it's\n// easier to handle this case. if(!global) { ...}\n\nmodule.exports = g;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar fetch_wrapper_1 = require(\"./fetch-wrapper\");\nexports.default = fetch_wrapper_1.default;\nexports.fetchMwOAuth2 = fetch_wrapper_1.default;\nexports.OAuth2 = fetch_wrapper_1.default;\nvar error_1 = require(\"./error\");\nexports.OAuth2Error = error_1.default;\n//# sourceMappingURL=index.js.map","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst base64_1 = require(\"./base64\");\nconst error_1 = __importDefault(require(\"./error\"));\nconst util_1 = require(\"./util\");\nclass OAuth2 {\n constructor(options) {\n this.options = options;\n this.token = {\n accessToken: options.accessToken || '',\n // If there was an accessToken we want to mark it as _not_ expired.\n // If there wasn't an access token we pretend it immediately expired.\n expiresAt: options.accessToken ? null : 0,\n refreshToken: options.refreshToken || null\n };\n }\n /**\n * Does a fetch request and adds a Bearer / access token.\n *\n * If the access token is not known, this function attempts to fetch it\n * first. If the access token is almost expiring, this function might attempt\n * to refresh it.\n */\n async fetch(input, init) {\n // input might be a string or a Request object, we want to make sure this\n // is always a fully-formed Request object.\n const request = new Request(input, init);\n let accessToken = await this.getAccessToken();\n let response = await requestWithBearerToken(request.clone(), accessToken);\n if (!response.ok && response.status === 401) {\n accessToken = await this.refreshToken();\n // We will try one more time\n response = await requestWithBearerToken(request, accessToken);\n }\n return response;\n }\n /**\n * Returns an access token.\n *\n * If the current access token is not known, it will attempt to fetch it.\n * If the access token is expiring, it will attempt to refresh it.\n */\n async getAccessToken() {\n if (this.token.expiresAt === null || this.token.expiresAt > Date.now()) {\n // The current token is still valid\n return this.token.accessToken;\n }\n return this.refreshToken();\n }\n /**\n * Forces an access token refresh\n */\n async refreshToken() {\n // The request body for the OAuth2 token endpoint\n let body;\n const previousToken = this.token;\n if (previousToken.refreshToken) {\n body = {\n grant_type: 'refresh_token',\n refresh_token: previousToken.refreshToken\n };\n if (!this.options.clientSecret) {\n // If there is no secret, it means we need to send the clientId along\n // in the body.\n body.client_id = this.options.clientId;\n }\n }\n else {\n switch (this.options.grantType) {\n case 'client_credentials':\n body = {\n grant_type: 'client_credentials',\n };\n if (this.options.scope) {\n body.scope = this.options.scope.join(' ');\n }\n break;\n case 'password':\n body = {\n grant_type: 'password',\n username: this.options.userName,\n password: this.options.password,\n };\n if (this.options.scope) {\n body.scope = this.options.scope.join(' ');\n }\n break;\n case 'authorization_code':\n body = {\n grant_type: 'authorization_code',\n code: this.options.code,\n redirect_uri: this.options.redirectUri,\n client_id: this.options.clientId,\n };\n break;\n default:\n throw new Error('Unknown grantType: ' + this.options.grantType);\n }\n }\n const headers = {\n 'Content-Type': 'application/x-www-form-urlencoded',\n };\n // @ts-ignore typescript doesn't like this but its the easiest way to do this.\n if (this.options.clientSecret !== undefined) {\n const basicAuthStr = base64_1.encode(this.options.clientId + ':' + this.options.clientSecret);\n headers.Authorization = 'Basic ' + basicAuthStr;\n }\n const authResult = await fetch(this.options.tokenEndpoint, {\n method: 'POST',\n headers,\n body: util_1.objToQueryString(body),\n });\n const jsonResult = await authResult.json();\n if (!authResult.ok) {\n // If we failed with a refresh_token grant_type, we're going to make one\n // more attempt doing a full re-auth\n if (body.grant_type === 'refresh_token' && this.options.grantType) {\n // Wiping out all old token info\n this.token = {\n accessToken: '',\n expiresAt: 0,\n refreshToken: null,\n };\n return this.getAccessToken();\n }\n let errorMessage = 'OAuth2 error ' + jsonResult.error + '.';\n if (jsonResult.error_description) {\n errorMessage += ' ' + jsonResult.error_description;\n }\n throw new error_1.default(errorMessage, jsonResult.error, authResult.status);\n }\n this.token = {\n accessToken: jsonResult.access_token,\n expiresAt: jsonResult.expires_in ? Date.now() + (jsonResult.expires_in * 1000) : null,\n refreshToken: jsonResult.refresh_token ? jsonResult.refresh_token : null,\n };\n if (this.options.onTokenUpdate) {\n this.options.onTokenUpdate(this.token);\n }\n return this.token.accessToken;\n }\n}\nexports.default = OAuth2;\nasync function requestWithBearerToken(request, accessToken) {\n request.headers.set('Authorization', 'Bearer ' + accessToken);\n return await fetch(request);\n}\n//# sourceMappingURL=fetch-wrapper.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * Encoding a string to base64 in a browser.\n */\nfunction encode(input) {\n return btoa(input);\n}\nexports.encode = encode;\n//# sourceMappingURL=base64.web.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * A simple querystring.stringify alternative, so we don't need to include\n * another dependency for the browser\n */\nfunction objToQueryString(input) {\n return Object.entries(input).map(([key, value]) => {\n if (value === undefined) {\n // skip\n return '';\n }\n else {\n return encodeURIComponent(key) + '=' + encodeURIComponent(value);\n }\n }).join('&');\n}\nexports.objToQueryString = objToQueryString;\n//# sourceMappingURL=util.js.map","/**\n * Encoding a string to base64 in a browser.\n */\nexport function encode(input: string): string {\n\n return btoa(input);\n\n}\n"],"sourceRoot":""}
\No newline at end of file