@xyo-network/api-call-witness 2.87.11 → 2.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Config.d.cts +24 -24
- package/dist/browser/Config.d.mts +24 -24
- package/dist/browser/Config.d.ts +24 -24
- package/dist/browser/Witness.d.cts.map +1 -1
- package/dist/browser/Witness.d.mts.map +1 -1
- package/dist/browser/Witness.d.ts.map +1 -1
- package/dist/browser/index.cjs +2 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +2 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Config.d.cts +24 -24
- package/dist/node/Config.d.mts +24 -24
- package/dist/node/Config.d.ts +24 -24
- package/dist/node/Witness.d.cts.map +1 -1
- package/dist/node/Witness.d.mts.map +1 -1
- package/dist/node/Witness.d.ts.map +1 -1
- package/dist/node/index.cjs +2 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +2 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +17 -16
- package/src/Witness.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Config.ts","../../src/Payload.ts","../../src/Witness.ts","../../src/lib/checkIpfsUrl.ts"],"sourcesContent":["import { AsObjectFactory } from '@xylabs/object'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessConfig } from '@xyo-network/witness-model'\n\nimport { ApiCall, ApiUriCall, ApiUriTemplateCall } from './Payload'\n\nexport const ApiCallWitnessConfigSchema = 'network.xyo.api.call.witness.config'\nexport type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema\n\nexport type ApiCallWitnessConfigBase = WitnessConfig<{\n accept?: 'application/json'\n queries?: ApiCall['queries']\n schema: ApiCallWitnessConfigSchema\n timeout?: number\n verb?: ApiCall['verb']\n}>\n\nexport type ApiUriCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n uri: ApiUriCall['uri']\n }\n>\n\nexport type ApiUriTemplateCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n params?: Record<string, unknown>\n uriTemplate: ApiUriTemplateCall['uriTemplate']\n }\n>\n\nexport type ApiCallWitnessConfig = ApiUriCallWitnessConfig | ApiUriTemplateCallWitnessConfig | ApiCallWitnessConfigBase\n\nexport const isApiCallWitnessConfig = isPayloadOfSchemaType<ApiCallWitnessConfig>(ApiCallWitnessConfigSchema)\nexport const asApiCallWitnessConfig = AsObjectFactory.create(isApiCallWitnessConfig)\n\nexport const isApiUriCallWitnessConfig = (value?: unknown): value is ApiUriCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriCallWitnessConfig).uri\nexport const asApiUriCallWitnessConfig = AsObjectFactory.create(isApiUriCallWitnessConfig)\n\nexport const isApiUriTemplateCallWitnessConfig = (value?: unknown): value is ApiUriTemplateCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriTemplateCallWitnessConfig).uriTemplate\nexport const asApiUriTemplateCallWitnessConfig = AsObjectFactory.create(isApiUriTemplateCallWitnessConfig)\n","import { Hash } from '@xylabs/hex'\nimport { AsObjectFactory, JsonArray, JsonObject } from '@xylabs/object'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nexport const ApiCallSchema = 'network.xyo.api.call'\nexport type ApiCallSchema = typeof ApiCallSchema\n\nexport type Verb = 'get' | 'post'\nexport type Queries = Record<string, string>\n\nexport interface ApiCallFields {\n queries?: Queries\n verb?: Verb\n}\n\nexport type ApiUriCall = Payload<\n ApiCallFields & {\n uri: string\n },\n ApiCallSchema\n>\nexport const isApiUriCall = (value?: unknown): value is ApiUriCall => isApiCall(value) && !!(value as ApiUriCall).uri\nexport const asApiUriCall = AsObjectFactory.create(isApiUriCall)\n\nexport type ApiUriTemplateCall = Payload<\n ApiCallFields & {\n params?: Record<string, unknown>\n uriTemplate?: string\n },\n ApiCallSchema\n>\nexport const isApiUriTemplateCall = (value?: unknown): value is ApiUriTemplateCall =>\n isApiCall(value) && !!((value as ApiUriTemplateCall).uriTemplate || (value as ApiUriTemplateCall).params)\nexport const asApiUriTemplateCall = AsObjectFactory.create(isApiUriTemplateCall)\n\nexport type ApiCall = ApiUriCall | ApiUriTemplateCall\n\nexport const ApiCallResultSchema = 'network.xyo.api.call.result'\nexport type ApiCallResultSchema = typeof ApiCallResultSchema\n\nexport const isApiCall = isPayloadOfSchemaType<ApiCall>(ApiCallSchema)\nexport const asApiCall = AsObjectFactory.create(isApiCall)\n\nexport interface HttpMeta {\n code?: string\n status?: number\n}\n\nexport type ApiCallJsonResultType = JsonArray | JsonObject\n\nexport type ApiCallJsonResult<T extends ApiCallJsonResultType = ApiCallJsonResultType> = Payload<\n {\n call: Hash\n contentType: 'application/json'\n data: T\n },\n ApiCallResultSchema\n>\n\nexport const isApiCallJsonResult = <T extends ApiCallJsonResultType = ApiCallJsonResultType>(x?: unknown | null): x is ApiCallJsonResult<T> => {\n return isPayloadOfSchemaType(ApiCallResultSchema)(x) && (x as ApiCallJsonResult)?.contentType === 'application/json'\n}\nexport const asApiCallJsonResult = AsObjectFactory.create(isApiCallJsonResult)\n\nexport type ApiCallBase64Result = Payload<\n {\n call: Hash\n contentType: Exclude<string, ApiCallJsonResult['contentType']>\n data: string\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallErrorResult = Payload<\n {\n call: Hash\n http?: HttpMeta\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallResult<TJson extends JsonArray | JsonObject = JsonArray | JsonObject> =\n | ApiCallBase64Result\n | ApiCallJsonResult<TJson>\n | ApiCallErrorResult\n\nexport const isApiCallResult = isPayloadOfSchemaType<ApiCallResult>(ApiCallResultSchema)\nexport const asApiCallResult = AsObjectFactory.create(isApiCallResult)\n","import { assertEx } from '@xylabs/assert'\nimport { Axios, AxiosError, AxiosJson } from '@xylabs/axios'\nimport { Hash } from '@xylabs/hex'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessParams } from '@xyo-network/witness-model'\nimport { fromByteArray } from 'base64-js'\nimport template from 'es6-template-strings'\n\nimport { ApiCallWitnessConfig, ApiCallWitnessConfigSchema, asApiUriCallWitnessConfig, asApiUriTemplateCallWitnessConfig } from './Config'\nimport { checkIpfsUrl } from './lib'\nimport {\n ApiCall,\n ApiCallBase64Result,\n ApiCallErrorResult,\n ApiCallJsonResult,\n ApiCallJsonResultType,\n ApiCallResult,\n ApiCallResultSchema,\n ApiCallSchema,\n asApiUriCall,\n asApiUriTemplateCall,\n} from './Payload'\n\nexport type ApiCallWitnessParams = WitnessParams<\n ApiCallWitnessConfig,\n {\n headers?: Record<string, string | undefined>\n ipfsGateway?: string\n }\n>\n\nexport class ApiCallWitness<TParams extends ApiCallWitnessParams = ApiCallWitnessParams> extends AbstractWitness<TParams, ApiCall, ApiCallResult> {\n static override configSchemas = [ApiCallWitnessConfigSchema]\n\n get accept() {\n return this.config.accept ?? 'application/json'\n }\n\n get ipfsGateway() {\n return this.params.ipfsGateway\n }\n\n get timeout() {\n return this.config.timeout\n }\n\n getFullUri(call?: ApiCall): string {\n const { uri: callUri } = asApiUriCall(call) ?? {}\n const { uriTemplate: callUriTemplate, params: callParams, queries: callQueries } = asApiUriTemplateCall(call) ?? {}\n const { uri: configUri } = asApiUriCallWitnessConfig(this.config) ?? {}\n const { uriTemplate: configUriTemplate, params: configParams, queries: configQueries } = asApiUriTemplateCallWitnessConfig(this.config) ?? {}\n\n const params = { ...configParams, ...callParams }\n\n let url: URL | undefined = undefined\n\n if (callUri) {\n url = new URL(callUri)\n } else if (callUriTemplate) {\n url = new URL(template(callUriTemplate, params))\n } else if (configUri) {\n url = new URL(configUri)\n } else if (configUriTemplate) {\n url = new URL(template(configUriTemplate, params))\n }\n\n if (url) {\n const queries = Object.entries({ ...configQueries, ...callQueries })\n queries.map(([key, value]) => url?.searchParams.set(key, value))\n return url.href\n }\n\n throw new Error('Unable to determine uri. No uri/uriTemplate specified in either the call or config.')\n }\n\n protected override async observeHandler(inPayloads: ApiCall[] = []): Promise<ApiCallResult[]> {\n await this.started('throw')\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType(ApiCallSchema)).map(async (call) => {\n const { verb: callVerb } = call\n const { verb: configVerb } = this.config\n const verb = callVerb ?? configVerb ?? 'get'\n const uri = this.getFullUri(call)\n\n const validatedUri = assertEx(checkIpfsUrl(uri, this.ipfsGateway), 'Invalid URI')\n\n if (verb === 'get') {\n return this.httpGet(validatedUri, uri)\n }\n\n const observation: ApiCallResult = {\n call: await PayloadHasher.hash(call),\n schema: ApiCallResultSchema,\n }\n return observation\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.error(`Error [${this.config.name}]: ${error.message}`)\n console.log(error.stack)\n throw error\n }\n }\n\n private async httpGet(url: string, call: Hash): Promise<ApiCallResult> {\n const result: ApiCallResult = {\n call,\n schema: ApiCallResultSchema,\n }\n try {\n switch (this.accept) {\n case 'application/json': {\n const axios = new AxiosJson({ headers: this.params.headers, timeout: this.timeout })\n const response = await axios.get<ApiCallJsonResultType>(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallJsonResult\n jsonResult.data = response.data\n jsonResult.contentType = 'application/json'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n default: {\n const axios = new Axios({ headers: this.params.headers, responseType: 'arraybuffer', timeout: this.timeout })\n const response = await axios.get(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallBase64Result\n jsonResult.data = fromByteArray(Buffer.from(response.data, 'binary'))\n jsonResult.contentType = response.headers['content-type']?.toString() ?? 'application/octet-stream'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n }\n } catch (ex) {\n const axiosError = ex as AxiosError\n if (axiosError.isAxiosError) {\n if (axiosError?.response?.status !== undefined) {\n result.http = result.http ?? {}\n result.http.status = axiosError?.response?.status\n }\n if (axiosError?.code !== undefined) {\n result.http = result.http ?? {}\n result.http.code = axiosError?.code\n }\n return result\n } else {\n throw ex\n }\n }\n return result\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nconst allowIpfsIoRepair = true\n\n/**\n * Returns the equivalent IPFS gateway URL for the supplied URL.\n * @param urlToCheck The URL to check\n * @returns If the supplied URL is an IPFS URL, it converts the URL to the\n * equivalent IPFS gateway URL. Otherwise, returns the original URL.\n */\nexport const checkIpfsUrl = (urlToCheck: string, ipfsGateway?: string): string => {\n try {\n const url = new URL(urlToCheck)\n let protocol = url.protocol\n let host = url.host\n let path = url.pathname\n const query = url.search\n if (protocol === 'ipfs:') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else if (allowIpfsIoRepair && protocol === 'https' && host === 'ipfs.io') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n const pathParts = path.split('/')\n if (pathParts[0] === 'ipfs') {\n pathParts.shift()\n }\n path = pathParts.join('/')\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else {\n return urlToCheck\n }\n } catch {\n //const error = ex as Error\n //console.error(`${error.name}:${error.message} [${urlToCheck}]`)\n //console.log(error.stack)\n return urlToCheck\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AAK/B,IAAM,6BAA6B;AA0BnC,IAAM,yBAAyB,sBAA4C,0BAA0B;AACrG,IAAM,yBAAyB,gBAAgB,OAAO,sBAAsB;AAE5E,IAAM,4BAA4B,CAAC,UACxC,uBAAuB,KAAK,KAAK,CAAC,CAAE,MAAkC;AACjE,IAAM,4BAA4B,gBAAgB,OAA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UAAI,WAAW,cAAc;AAC3B,YAAI,YAAY,UAAU,WAAW,QAAW;AAC9C,iBAAO,OAAO,OAAO,QAAQ,CAAC;AAC9B,iBAAO,KAAK,SAAS,YAAY,UAAU;AAAA,QAC7C;AACA,YAAI,YAAY,SAAS,QAAW;AAClC,iBAAO,OAAO,OAAO,QAAQ,CAAC;AAC9B,iBAAO,KAAK,OAAO,YAAY;AAAA,QACjC;AACA,eAAO;AAAA,MACT,OAAO;AACL,cAAM;AAAA,MACR;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["AsObjectFactory","isPayloadOfSchemaType","assertEx","isPayloadOfSchemaType","isPayloadOfSchemaType","assertEx"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Config.ts","../../src/Payload.ts","../../src/Witness.ts","../../src/lib/checkIpfsUrl.ts"],"sourcesContent":["import { AsObjectFactory } from '@xylabs/object'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessConfig } from '@xyo-network/witness-model'\n\nimport { ApiCall, ApiUriCall, ApiUriTemplateCall } from './Payload'\n\nexport const ApiCallWitnessConfigSchema = 'network.xyo.api.call.witness.config'\nexport type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema\n\nexport type ApiCallWitnessConfigBase = WitnessConfig<{\n accept?: 'application/json'\n queries?: ApiCall['queries']\n schema: ApiCallWitnessConfigSchema\n timeout?: number\n verb?: ApiCall['verb']\n}>\n\nexport type ApiUriCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n uri: ApiUriCall['uri']\n }\n>\n\nexport type ApiUriTemplateCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n params?: Record<string, unknown>\n uriTemplate: ApiUriTemplateCall['uriTemplate']\n }\n>\n\nexport type ApiCallWitnessConfig = ApiUriCallWitnessConfig | ApiUriTemplateCallWitnessConfig | ApiCallWitnessConfigBase\n\nexport const isApiCallWitnessConfig = isPayloadOfSchemaType<ApiCallWitnessConfig>(ApiCallWitnessConfigSchema)\nexport const asApiCallWitnessConfig = AsObjectFactory.create(isApiCallWitnessConfig)\n\nexport const isApiUriCallWitnessConfig = (value?: unknown): value is ApiUriCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriCallWitnessConfig).uri\nexport const asApiUriCallWitnessConfig = AsObjectFactory.create(isApiUriCallWitnessConfig)\n\nexport const isApiUriTemplateCallWitnessConfig = (value?: unknown): value is ApiUriTemplateCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriTemplateCallWitnessConfig).uriTemplate\nexport const asApiUriTemplateCallWitnessConfig = AsObjectFactory.create(isApiUriTemplateCallWitnessConfig)\n","import { Hash } from '@xylabs/hex'\nimport { AsObjectFactory, JsonArray, JsonObject } from '@xylabs/object'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nexport const ApiCallSchema = 'network.xyo.api.call'\nexport type ApiCallSchema = typeof ApiCallSchema\n\nexport type Verb = 'get' | 'post'\nexport type Queries = Record<string, string>\n\nexport interface ApiCallFields {\n queries?: Queries\n verb?: Verb\n}\n\nexport type ApiUriCall = Payload<\n ApiCallFields & {\n uri: string\n },\n ApiCallSchema\n>\nexport const isApiUriCall = (value?: unknown): value is ApiUriCall => isApiCall(value) && !!(value as ApiUriCall).uri\nexport const asApiUriCall = AsObjectFactory.create(isApiUriCall)\n\nexport type ApiUriTemplateCall = Payload<\n ApiCallFields & {\n params?: Record<string, unknown>\n uriTemplate?: string\n },\n ApiCallSchema\n>\nexport const isApiUriTemplateCall = (value?: unknown): value is ApiUriTemplateCall =>\n isApiCall(value) && !!((value as ApiUriTemplateCall).uriTemplate || (value as ApiUriTemplateCall).params)\nexport const asApiUriTemplateCall = AsObjectFactory.create(isApiUriTemplateCall)\n\nexport type ApiCall = ApiUriCall | ApiUriTemplateCall\n\nexport const ApiCallResultSchema = 'network.xyo.api.call.result'\nexport type ApiCallResultSchema = typeof ApiCallResultSchema\n\nexport const isApiCall = isPayloadOfSchemaType<ApiCall>(ApiCallSchema)\nexport const asApiCall = AsObjectFactory.create(isApiCall)\n\nexport interface HttpMeta {\n code?: string\n status?: number\n}\n\nexport type ApiCallJsonResultType = JsonArray | JsonObject\n\nexport type ApiCallJsonResult<T extends ApiCallJsonResultType = ApiCallJsonResultType> = Payload<\n {\n call: Hash\n contentType: 'application/json'\n data: T\n },\n ApiCallResultSchema\n>\n\nexport const isApiCallJsonResult = <T extends ApiCallJsonResultType = ApiCallJsonResultType>(x?: unknown | null): x is ApiCallJsonResult<T> => {\n return isPayloadOfSchemaType(ApiCallResultSchema)(x) && (x as ApiCallJsonResult)?.contentType === 'application/json'\n}\nexport const asApiCallJsonResult = AsObjectFactory.create(isApiCallJsonResult)\n\nexport type ApiCallBase64Result = Payload<\n {\n call: Hash\n contentType: Exclude<string, ApiCallJsonResult['contentType']>\n data: string\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallErrorResult = Payload<\n {\n call: Hash\n http?: HttpMeta\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallResult<TJson extends JsonArray | JsonObject = JsonArray | JsonObject> =\n | ApiCallBase64Result\n | ApiCallJsonResult<TJson>\n | ApiCallErrorResult\n\nexport const isApiCallResult = isPayloadOfSchemaType<ApiCallResult>(ApiCallResultSchema)\nexport const asApiCallResult = AsObjectFactory.create(isApiCallResult)\n","import { assertEx } from '@xylabs/assert'\nimport { Axios, AxiosError, AxiosJson } from '@xylabs/axios'\nimport { Hash } from '@xylabs/hex'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessParams } from '@xyo-network/witness-model'\nimport { fromByteArray } from 'base64-js'\nimport template from 'es6-template-strings'\n\nimport { ApiCallWitnessConfig, ApiCallWitnessConfigSchema, asApiUriCallWitnessConfig, asApiUriTemplateCallWitnessConfig } from './Config'\nimport { checkIpfsUrl } from './lib'\nimport {\n ApiCall,\n ApiCallBase64Result,\n ApiCallErrorResult,\n ApiCallJsonResult,\n ApiCallJsonResultType,\n ApiCallResult,\n ApiCallResultSchema,\n ApiCallSchema,\n asApiUriCall,\n asApiUriTemplateCall,\n} from './Payload'\n\nexport type ApiCallWitnessParams = WitnessParams<\n ApiCallWitnessConfig,\n {\n headers?: Record<string, string | undefined>\n ipfsGateway?: string\n }\n>\n\nexport class ApiCallWitness<TParams extends ApiCallWitnessParams = ApiCallWitnessParams> extends AbstractWitness<TParams, ApiCall, ApiCallResult> {\n static override configSchemas = [ApiCallWitnessConfigSchema]\n\n get accept() {\n return this.config.accept ?? 'application/json'\n }\n\n get ipfsGateway() {\n return this.params.ipfsGateway\n }\n\n get timeout() {\n return this.config.timeout\n }\n\n getFullUri(call?: ApiCall): string {\n const { uri: callUri } = asApiUriCall(call) ?? {}\n const { uriTemplate: callUriTemplate, params: callParams, queries: callQueries } = asApiUriTemplateCall(call) ?? {}\n const { uri: configUri } = asApiUriCallWitnessConfig(this.config) ?? {}\n const { uriTemplate: configUriTemplate, params: configParams, queries: configQueries } = asApiUriTemplateCallWitnessConfig(this.config) ?? {}\n\n const params = { ...configParams, ...callParams }\n\n let url: URL | undefined = undefined\n\n if (callUri) {\n url = new URL(callUri)\n } else if (callUriTemplate) {\n url = new URL(template(callUriTemplate, params))\n } else if (configUri) {\n url = new URL(configUri)\n } else if (configUriTemplate) {\n url = new URL(template(configUriTemplate, params))\n }\n\n if (url) {\n const queries = Object.entries({ ...configQueries, ...callQueries })\n queries.map(([key, value]) => url?.searchParams.set(key, value))\n return url.href\n }\n\n throw new Error('Unable to determine uri. No uri/uriTemplate specified in either the call or config.')\n }\n\n protected override async observeHandler(inPayloads: ApiCall[] = []): Promise<ApiCallResult[]> {\n await this.started('throw')\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType(ApiCallSchema)).map(async (call) => {\n const { verb: callVerb } = call\n const { verb: configVerb } = this.config\n const verb = callVerb ?? configVerb ?? 'get'\n const uri = this.getFullUri(call)\n\n const validatedUri = assertEx(checkIpfsUrl(uri, this.ipfsGateway), 'Invalid URI')\n\n if (verb === 'get') {\n return this.httpGet(validatedUri, (await PayloadBuilder.build(call)).$hash)\n }\n\n const observation: ApiCallResult = {\n call: await PayloadHasher.hash(call),\n schema: ApiCallResultSchema,\n }\n return observation\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.error(`Error [${this.config.name}]: ${error.message}`)\n console.log(error.stack)\n throw error\n }\n }\n\n private async httpGet(url: string, call: Hash): Promise<ApiCallResult> {\n const result: ApiCallResult = {\n call,\n schema: ApiCallResultSchema,\n }\n try {\n switch (this.accept) {\n case 'application/json': {\n const axios = new AxiosJson({ headers: this.params.headers, timeout: this.timeout })\n const response = await axios.get<ApiCallJsonResultType>(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallJsonResult\n jsonResult.data = response.data\n jsonResult.contentType = 'application/json'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n default: {\n const axios = new Axios({ headers: this.params.headers, responseType: 'arraybuffer', timeout: this.timeout })\n const response = await axios.get(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallBase64Result\n jsonResult.data = fromByteArray(Buffer.from(response.data, 'binary'))\n jsonResult.contentType = response.headers['content-type']?.toString() ?? 'application/octet-stream'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n }\n } catch (ex) {\n const axiosError = ex as AxiosError\n if (axiosError.isAxiosError) {\n if (axiosError?.response?.status !== undefined) {\n result.http = result.http ?? {}\n result.http.status = axiosError?.response?.status\n }\n if (axiosError?.code !== undefined) {\n result.http = result.http ?? {}\n result.http.code = axiosError?.code\n }\n return result\n } else {\n throw ex\n }\n }\n return result\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nconst allowIpfsIoRepair = true\n\n/**\n * Returns the equivalent IPFS gateway URL for the supplied URL.\n * @param urlToCheck The URL to check\n * @returns If the supplied URL is an IPFS URL, it converts the URL to the\n * equivalent IPFS gateway URL. Otherwise, returns the original URL.\n */\nexport const checkIpfsUrl = (urlToCheck: string, ipfsGateway?: string): string => {\n try {\n const url = new URL(urlToCheck)\n let protocol = url.protocol\n let host = url.host\n let path = url.pathname\n const query = url.search\n if (protocol === 'ipfs:') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else if (allowIpfsIoRepair && protocol === 'https' && host === 'ipfs.io') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n const pathParts = path.split('/')\n if (pathParts[0] === 'ipfs') {\n pathParts.shift()\n }\n path = pathParts.join('/')\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else {\n return urlToCheck\n }\n } catch {\n //const error = ex as Error\n //console.error(`${error.name}:${error.message} [${urlToCheck}]`)\n //console.log(error.stack)\n return urlToCheck\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AAK/B,IAAM,6BAA6B;AA0BnC,IAAM,yBAAyB,sBAA4C,0BAA0B;AACrG,IAAM,yBAAyB,gBAAgB,OAAO,sBAAsB;AAE5E,IAAM,4BAA4B,CAAC,UACxC,uBAAuB,KAAK,KAAK,CAAC,CAAE,MAAkC;AACjE,IAAM,4BAA4B,gBAAgB,OAAO,yBAAyB;AAElF,IAAM,oCAAoC,CAAC,UAChD,uBAAuB,KAAK,KAAK,CAAC,CAAE,MAA0C;AACzE,IAAM,oCAAoC,gBAAgB,OAAO,iCAAiC;;;ACxCzG,SAAS,mBAAAA,wBAA8C;AACvD,SAAS,yBAAAC,8BAAsC;AAExC,IAAM,gBAAgB;AA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AAY,SAAS,QAAW;AAClC,iBAAO,OAAO,OAAO,QAAQ,CAAC;AAC9B,iBAAO,KAAK,OAAO,YAAY;AAAA,QACjC;AACA,eAAO;AAAA,MACT,OAAO;AACL,cAAM;AAAA,MACR;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["AsObjectFactory","isPayloadOfSchemaType","assertEx","isPayloadOfSchemaType","isPayloadOfSchemaType","assertEx"]}
|
package/dist/node/Config.d.cts
CHANGED
|
@@ -33,8 +33,8 @@ export declare const isApiUriCallWitnessConfig: (value?: unknown) => value is im
|
|
|
33
33
|
schema: "network.xyo.api.call.witness.config";
|
|
34
34
|
readonly security?: {
|
|
35
35
|
readonly allowAnonymous?: boolean | undefined;
|
|
36
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
37
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
36
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
37
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
38
38
|
} | undefined;
|
|
39
39
|
readonly sign?: boolean | undefined;
|
|
40
40
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -52,8 +52,8 @@ export declare const isApiUriCallWitnessConfig: (value?: unknown) => value is im
|
|
|
52
52
|
schema: "network.xyo.api.call.witness.config";
|
|
53
53
|
readonly security?: {
|
|
54
54
|
readonly allowAnonymous?: boolean | undefined;
|
|
55
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
56
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
55
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
56
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
57
57
|
} | undefined;
|
|
58
58
|
readonly sign?: boolean | undefined;
|
|
59
59
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -81,8 +81,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
81
81
|
schema: "network.xyo.api.call.witness.config";
|
|
82
82
|
readonly security?: {
|
|
83
83
|
readonly allowAnonymous?: boolean | undefined;
|
|
84
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
85
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
84
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
85
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
86
86
|
} | undefined;
|
|
87
87
|
readonly sign?: boolean | undefined;
|
|
88
88
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -100,8 +100,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
100
100
|
schema: "network.xyo.api.call.witness.config";
|
|
101
101
|
readonly security?: {
|
|
102
102
|
readonly allowAnonymous?: boolean | undefined;
|
|
103
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
104
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
103
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
104
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
105
105
|
} | undefined;
|
|
106
106
|
readonly sign?: boolean | undefined;
|
|
107
107
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -128,8 +128,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
128
128
|
schema: "network.xyo.api.call.witness.config";
|
|
129
129
|
readonly security?: {
|
|
130
130
|
readonly allowAnonymous?: boolean | undefined;
|
|
131
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
132
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
131
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
132
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
133
133
|
} | undefined;
|
|
134
134
|
readonly sign?: boolean | undefined;
|
|
135
135
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -147,8 +147,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
147
147
|
schema: "network.xyo.api.call.witness.config";
|
|
148
148
|
readonly security?: {
|
|
149
149
|
readonly allowAnonymous?: boolean | undefined;
|
|
150
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
151
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
150
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
151
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
152
152
|
} | undefined;
|
|
153
153
|
readonly sign?: boolean | undefined;
|
|
154
154
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -176,8 +176,8 @@ export declare const isApiUriTemplateCallWitnessConfig: (value?: unknown) => val
|
|
|
176
176
|
schema: "network.xyo.api.call.witness.config";
|
|
177
177
|
readonly security?: {
|
|
178
178
|
readonly allowAnonymous?: boolean | undefined;
|
|
179
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
180
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
179
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
180
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
181
181
|
} | undefined;
|
|
182
182
|
readonly sign?: boolean | undefined;
|
|
183
183
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -195,8 +195,8 @@ export declare const isApiUriTemplateCallWitnessConfig: (value?: unknown) => val
|
|
|
195
195
|
schema: "network.xyo.api.call.witness.config";
|
|
196
196
|
readonly security?: {
|
|
197
197
|
readonly allowAnonymous?: boolean | undefined;
|
|
198
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
199
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
198
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
199
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
200
200
|
} | undefined;
|
|
201
201
|
readonly sign?: boolean | undefined;
|
|
202
202
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -225,8 +225,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
225
225
|
schema: "network.xyo.api.call.witness.config";
|
|
226
226
|
readonly security?: {
|
|
227
227
|
readonly allowAnonymous?: boolean | undefined;
|
|
228
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
229
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
228
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
229
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
230
230
|
} | undefined;
|
|
231
231
|
readonly sign?: boolean | undefined;
|
|
232
232
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -244,8 +244,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
244
244
|
schema: "network.xyo.api.call.witness.config";
|
|
245
245
|
readonly security?: {
|
|
246
246
|
readonly allowAnonymous?: boolean | undefined;
|
|
247
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
248
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
247
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
248
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
249
249
|
} | undefined;
|
|
250
250
|
readonly sign?: boolean | undefined;
|
|
251
251
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -273,8 +273,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
273
273
|
schema: "network.xyo.api.call.witness.config";
|
|
274
274
|
readonly security?: {
|
|
275
275
|
readonly allowAnonymous?: boolean | undefined;
|
|
276
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
277
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
276
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
277
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
278
278
|
} | undefined;
|
|
279
279
|
readonly sign?: boolean | undefined;
|
|
280
280
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -292,8 +292,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
292
292
|
schema: "network.xyo.api.call.witness.config";
|
|
293
293
|
readonly security?: {
|
|
294
294
|
readonly allowAnonymous?: boolean | undefined;
|
|
295
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
296
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
295
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
296
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
297
297
|
} | undefined;
|
|
298
298
|
readonly sign?: boolean | undefined;
|
|
299
299
|
readonly storeQueries?: boolean | undefined;
|
package/dist/node/Config.d.mts
CHANGED
|
@@ -33,8 +33,8 @@ export declare const isApiUriCallWitnessConfig: (value?: unknown) => value is im
|
|
|
33
33
|
schema: "network.xyo.api.call.witness.config";
|
|
34
34
|
readonly security?: {
|
|
35
35
|
readonly allowAnonymous?: boolean | undefined;
|
|
36
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
37
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
36
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
37
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
38
38
|
} | undefined;
|
|
39
39
|
readonly sign?: boolean | undefined;
|
|
40
40
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -52,8 +52,8 @@ export declare const isApiUriCallWitnessConfig: (value?: unknown) => value is im
|
|
|
52
52
|
schema: "network.xyo.api.call.witness.config";
|
|
53
53
|
readonly security?: {
|
|
54
54
|
readonly allowAnonymous?: boolean | undefined;
|
|
55
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
56
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
55
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
56
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
57
57
|
} | undefined;
|
|
58
58
|
readonly sign?: boolean | undefined;
|
|
59
59
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -81,8 +81,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
81
81
|
schema: "network.xyo.api.call.witness.config";
|
|
82
82
|
readonly security?: {
|
|
83
83
|
readonly allowAnonymous?: boolean | undefined;
|
|
84
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
85
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
84
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
85
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
86
86
|
} | undefined;
|
|
87
87
|
readonly sign?: boolean | undefined;
|
|
88
88
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -100,8 +100,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
100
100
|
schema: "network.xyo.api.call.witness.config";
|
|
101
101
|
readonly security?: {
|
|
102
102
|
readonly allowAnonymous?: boolean | undefined;
|
|
103
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
104
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
103
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
104
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
105
105
|
} | undefined;
|
|
106
106
|
readonly sign?: boolean | undefined;
|
|
107
107
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -128,8 +128,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
128
128
|
schema: "network.xyo.api.call.witness.config";
|
|
129
129
|
readonly security?: {
|
|
130
130
|
readonly allowAnonymous?: boolean | undefined;
|
|
131
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
132
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
131
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
132
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
133
133
|
} | undefined;
|
|
134
134
|
readonly sign?: boolean | undefined;
|
|
135
135
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -147,8 +147,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
147
147
|
schema: "network.xyo.api.call.witness.config";
|
|
148
148
|
readonly security?: {
|
|
149
149
|
readonly allowAnonymous?: boolean | undefined;
|
|
150
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
151
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
150
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
151
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
152
152
|
} | undefined;
|
|
153
153
|
readonly sign?: boolean | undefined;
|
|
154
154
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -176,8 +176,8 @@ export declare const isApiUriTemplateCallWitnessConfig: (value?: unknown) => val
|
|
|
176
176
|
schema: "network.xyo.api.call.witness.config";
|
|
177
177
|
readonly security?: {
|
|
178
178
|
readonly allowAnonymous?: boolean | undefined;
|
|
179
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
180
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
179
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
180
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
181
181
|
} | undefined;
|
|
182
182
|
readonly sign?: boolean | undefined;
|
|
183
183
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -195,8 +195,8 @@ export declare const isApiUriTemplateCallWitnessConfig: (value?: unknown) => val
|
|
|
195
195
|
schema: "network.xyo.api.call.witness.config";
|
|
196
196
|
readonly security?: {
|
|
197
197
|
readonly allowAnonymous?: boolean | undefined;
|
|
198
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
199
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
198
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
199
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
200
200
|
} | undefined;
|
|
201
201
|
readonly sign?: boolean | undefined;
|
|
202
202
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -225,8 +225,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
225
225
|
schema: "network.xyo.api.call.witness.config";
|
|
226
226
|
readonly security?: {
|
|
227
227
|
readonly allowAnonymous?: boolean | undefined;
|
|
228
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
229
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
228
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
229
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
230
230
|
} | undefined;
|
|
231
231
|
readonly sign?: boolean | undefined;
|
|
232
232
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -244,8 +244,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
244
244
|
schema: "network.xyo.api.call.witness.config";
|
|
245
245
|
readonly security?: {
|
|
246
246
|
readonly allowAnonymous?: boolean | undefined;
|
|
247
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
248
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
247
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
248
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
249
249
|
} | undefined;
|
|
250
250
|
readonly sign?: boolean | undefined;
|
|
251
251
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -273,8 +273,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
273
273
|
schema: "network.xyo.api.call.witness.config";
|
|
274
274
|
readonly security?: {
|
|
275
275
|
readonly allowAnonymous?: boolean | undefined;
|
|
276
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
277
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
276
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
277
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
278
278
|
} | undefined;
|
|
279
279
|
readonly sign?: boolean | undefined;
|
|
280
280
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -292,8 +292,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
292
292
|
schema: "network.xyo.api.call.witness.config";
|
|
293
293
|
readonly security?: {
|
|
294
294
|
readonly allowAnonymous?: boolean | undefined;
|
|
295
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
296
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
295
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
296
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
297
297
|
} | undefined;
|
|
298
298
|
readonly sign?: boolean | undefined;
|
|
299
299
|
readonly storeQueries?: boolean | undefined;
|
package/dist/node/Config.d.ts
CHANGED
|
@@ -33,8 +33,8 @@ export declare const isApiUriCallWitnessConfig: (value?: unknown) => value is im
|
|
|
33
33
|
schema: "network.xyo.api.call.witness.config";
|
|
34
34
|
readonly security?: {
|
|
35
35
|
readonly allowAnonymous?: boolean | undefined;
|
|
36
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
37
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
36
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
37
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
38
38
|
} | undefined;
|
|
39
39
|
readonly sign?: boolean | undefined;
|
|
40
40
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -52,8 +52,8 @@ export declare const isApiUriCallWitnessConfig: (value?: unknown) => value is im
|
|
|
52
52
|
schema: "network.xyo.api.call.witness.config";
|
|
53
53
|
readonly security?: {
|
|
54
54
|
readonly allowAnonymous?: boolean | undefined;
|
|
55
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
56
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
55
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
56
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
57
57
|
} | undefined;
|
|
58
58
|
readonly sign?: boolean | undefined;
|
|
59
59
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -81,8 +81,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
81
81
|
schema: "network.xyo.api.call.witness.config";
|
|
82
82
|
readonly security?: {
|
|
83
83
|
readonly allowAnonymous?: boolean | undefined;
|
|
84
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
85
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
84
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
85
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
86
86
|
} | undefined;
|
|
87
87
|
readonly sign?: boolean | undefined;
|
|
88
88
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -100,8 +100,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
100
100
|
schema: "network.xyo.api.call.witness.config";
|
|
101
101
|
readonly security?: {
|
|
102
102
|
readonly allowAnonymous?: boolean | undefined;
|
|
103
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
104
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
103
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
104
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
105
105
|
} | undefined;
|
|
106
106
|
readonly sign?: boolean | undefined;
|
|
107
107
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -128,8 +128,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
128
128
|
schema: "network.xyo.api.call.witness.config";
|
|
129
129
|
readonly security?: {
|
|
130
130
|
readonly allowAnonymous?: boolean | undefined;
|
|
131
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
132
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
131
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
132
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
133
133
|
} | undefined;
|
|
134
134
|
readonly sign?: boolean | undefined;
|
|
135
135
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -147,8 +147,8 @@ export declare const asApiUriCallWitnessConfig: {
|
|
|
147
147
|
schema: "network.xyo.api.call.witness.config";
|
|
148
148
|
readonly security?: {
|
|
149
149
|
readonly allowAnonymous?: boolean | undefined;
|
|
150
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
151
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
150
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
151
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
152
152
|
} | undefined;
|
|
153
153
|
readonly sign?: boolean | undefined;
|
|
154
154
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -176,8 +176,8 @@ export declare const isApiUriTemplateCallWitnessConfig: (value?: unknown) => val
|
|
|
176
176
|
schema: "network.xyo.api.call.witness.config";
|
|
177
177
|
readonly security?: {
|
|
178
178
|
readonly allowAnonymous?: boolean | undefined;
|
|
179
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
180
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
179
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
180
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
181
181
|
} | undefined;
|
|
182
182
|
readonly sign?: boolean | undefined;
|
|
183
183
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -195,8 +195,8 @@ export declare const isApiUriTemplateCallWitnessConfig: (value?: unknown) => val
|
|
|
195
195
|
schema: "network.xyo.api.call.witness.config";
|
|
196
196
|
readonly security?: {
|
|
197
197
|
readonly allowAnonymous?: boolean | undefined;
|
|
198
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
199
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
198
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
199
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
200
200
|
} | undefined;
|
|
201
201
|
readonly sign?: boolean | undefined;
|
|
202
202
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -225,8 +225,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
225
225
|
schema: "network.xyo.api.call.witness.config";
|
|
226
226
|
readonly security?: {
|
|
227
227
|
readonly allowAnonymous?: boolean | undefined;
|
|
228
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
229
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
228
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
229
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
230
230
|
} | undefined;
|
|
231
231
|
readonly sign?: boolean | undefined;
|
|
232
232
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -244,8 +244,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
244
244
|
schema: "network.xyo.api.call.witness.config";
|
|
245
245
|
readonly security?: {
|
|
246
246
|
readonly allowAnonymous?: boolean | undefined;
|
|
247
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
248
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
247
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
248
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
249
249
|
} | undefined;
|
|
250
250
|
readonly sign?: boolean | undefined;
|
|
251
251
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -273,8 +273,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
273
273
|
schema: "network.xyo.api.call.witness.config";
|
|
274
274
|
readonly security?: {
|
|
275
275
|
readonly allowAnonymous?: boolean | undefined;
|
|
276
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
277
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
276
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
277
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
278
278
|
} | undefined;
|
|
279
279
|
readonly sign?: boolean | undefined;
|
|
280
280
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -292,8 +292,8 @@ export declare const asApiUriTemplateCallWitnessConfig: {
|
|
|
292
292
|
schema: "network.xyo.api.call.witness.config";
|
|
293
293
|
readonly security?: {
|
|
294
294
|
readonly allowAnonymous?: boolean | undefined;
|
|
295
|
-
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
296
|
-
readonly disallowed?: Record<string, string[]> | undefined;
|
|
295
|
+
readonly allowed?: Record<string, (Lowercase<string> | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
296
|
+
readonly disallowed?: Record<string, Lowercase<string>[]> | undefined;
|
|
297
297
|
} | undefined;
|
|
298
298
|
readonly sign?: boolean | undefined;
|
|
299
299
|
readonly storeQueries?: boolean | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAI/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,OAAO,EAAE,oBAAoB,EAA4F,MAAM,UAAU,CAAA;AAEzI,OAAO,EACL,OAAO,EAKP,aAAa,EAKd,MAAM,WAAW,CAAA;AAElB,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,oBAAoB,EACpB;IACE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CACF,CAAA;AAED,qBAAa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC;IAC/I,OAAgB,aAAa,WAA+B;IAE5D,IAAI,MAAM,uBAET;IAED,IAAI,WAAW,uBAEd;IAED,IAAI,OAAO,uBAEV;IAED,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM;cA6BT,cAAc,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YAgC/E,OAAO;CAwDtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAI/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,OAAO,EAAE,oBAAoB,EAA4F,MAAM,UAAU,CAAA;AAEzI,OAAO,EACL,OAAO,EAKP,aAAa,EAKd,MAAM,WAAW,CAAA;AAElB,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,oBAAoB,EACpB;IACE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CACF,CAAA;AAED,qBAAa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC;IAC/I,OAAgB,aAAa,WAA+B;IAE5D,IAAI,MAAM,uBAET;IAED,IAAI,WAAW,uBAEd;IAED,IAAI,OAAO,uBAEV;IAED,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM;cA6BT,cAAc,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YAgC/E,OAAO;CAwDtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAI/D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAI1D,OAAO,EAAE,oBAAoB,EAA4F,MAAM,UAAU,CAAA;AAEzI,OAAO,EACL,OAAO,EAKP,aAAa,EAKd,MAAM,WAAW,CAAA;AAElB,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,oBAAoB,EACpB;IACE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CACF,CAAA;AAED,qBAAa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC;IAC/I,OAAgB,aAAa,WAA+B;IAE5D,IAAI,MAAM,uBAET;IAED,IAAI,WAAW,uBAEd;IAED,IAAI,OAAO,uBAEV;IAED,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM;cA6BT,cAAc,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YAgC/E,OAAO;CAwDtB"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -87,6 +87,7 @@ var import_assert2 = require("@xylabs/assert");
|
|
|
87
87
|
var import_axios = require("@xylabs/axios");
|
|
88
88
|
var import_abstract_witness = require("@xyo-network/abstract-witness");
|
|
89
89
|
var import_hash = require("@xyo-network/hash");
|
|
90
|
+
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
90
91
|
var import_payload_model3 = require("@xyo-network/payload-model");
|
|
91
92
|
var import_base64_js = require("base64-js");
|
|
92
93
|
var import_es6_template_strings = __toESM(require("es6-template-strings"), 1);
|
|
@@ -171,7 +172,7 @@ var ApiCallWitness = class extends import_abstract_witness.AbstractWitness {
|
|
|
171
172
|
const uri = this.getFullUri(call);
|
|
172
173
|
const validatedUri = (0, import_assert2.assertEx)(checkIpfsUrl(uri, this.ipfsGateway), "Invalid URI");
|
|
173
174
|
if (verb === "get") {
|
|
174
|
-
return this.httpGet(validatedUri,
|
|
175
|
+
return this.httpGet(validatedUri, (await import_payload_builder.PayloadBuilder.build(call)).$hash);
|
|
175
176
|
}
|
|
176
177
|
const observation = {
|
|
177
178
|
call: await import_hash.PayloadHasher.hash(call),
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Config.ts","../../src/Payload.ts","../../src/Witness.ts","../../src/lib/checkIpfsUrl.ts"],"sourcesContent":["export * from './Config'\nexport * from './Payload'\nexport * from './Witness'\n","import { AsObjectFactory } from '@xylabs/object'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessConfig } from '@xyo-network/witness-model'\n\nimport { ApiCall, ApiUriCall, ApiUriTemplateCall } from './Payload'\n\nexport const ApiCallWitnessConfigSchema = 'network.xyo.api.call.witness.config'\nexport type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema\n\nexport type ApiCallWitnessConfigBase = WitnessConfig<{\n accept?: 'application/json'\n queries?: ApiCall['queries']\n schema: ApiCallWitnessConfigSchema\n timeout?: number\n verb?: ApiCall['verb']\n}>\n\nexport type ApiUriCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n uri: ApiUriCall['uri']\n }\n>\n\nexport type ApiUriTemplateCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n params?: Record<string, unknown>\n uriTemplate: ApiUriTemplateCall['uriTemplate']\n }\n>\n\nexport type ApiCallWitnessConfig = ApiUriCallWitnessConfig | ApiUriTemplateCallWitnessConfig | ApiCallWitnessConfigBase\n\nexport const isApiCallWitnessConfig = isPayloadOfSchemaType<ApiCallWitnessConfig>(ApiCallWitnessConfigSchema)\nexport const asApiCallWitnessConfig = AsObjectFactory.create(isApiCallWitnessConfig)\n\nexport const isApiUriCallWitnessConfig = (value?: unknown): value is ApiUriCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriCallWitnessConfig).uri\nexport const asApiUriCallWitnessConfig = AsObjectFactory.create(isApiUriCallWitnessConfig)\n\nexport const isApiUriTemplateCallWitnessConfig = (value?: unknown): value is ApiUriTemplateCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriTemplateCallWitnessConfig).uriTemplate\nexport const asApiUriTemplateCallWitnessConfig = AsObjectFactory.create(isApiUriTemplateCallWitnessConfig)\n","import { Hash } from '@xylabs/hex'\nimport { AsObjectFactory, JsonArray, JsonObject } from '@xylabs/object'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nexport const ApiCallSchema = 'network.xyo.api.call'\nexport type ApiCallSchema = typeof ApiCallSchema\n\nexport type Verb = 'get' | 'post'\nexport type Queries = Record<string, string>\n\nexport interface ApiCallFields {\n queries?: Queries\n verb?: Verb\n}\n\nexport type ApiUriCall = Payload<\n ApiCallFields & {\n uri: string\n },\n ApiCallSchema\n>\nexport const isApiUriCall = (value?: unknown): value is ApiUriCall => isApiCall(value) && !!(value as ApiUriCall).uri\nexport const asApiUriCall = AsObjectFactory.create(isApiUriCall)\n\nexport type ApiUriTemplateCall = Payload<\n ApiCallFields & {\n params?: Record<string, unknown>\n uriTemplate?: string\n },\n ApiCallSchema\n>\nexport const isApiUriTemplateCall = (value?: unknown): value is ApiUriTemplateCall =>\n isApiCall(value) && !!((value as ApiUriTemplateCall).uriTemplate || (value as ApiUriTemplateCall).params)\nexport const asApiUriTemplateCall = AsObjectFactory.create(isApiUriTemplateCall)\n\nexport type ApiCall = ApiUriCall | ApiUriTemplateCall\n\nexport const ApiCallResultSchema = 'network.xyo.api.call.result'\nexport type ApiCallResultSchema = typeof ApiCallResultSchema\n\nexport const isApiCall = isPayloadOfSchemaType<ApiCall>(ApiCallSchema)\nexport const asApiCall = AsObjectFactory.create(isApiCall)\n\nexport interface HttpMeta {\n code?: string\n status?: number\n}\n\nexport type ApiCallJsonResultType = JsonArray | JsonObject\n\nexport type ApiCallJsonResult<T extends ApiCallJsonResultType = ApiCallJsonResultType> = Payload<\n {\n call: Hash\n contentType: 'application/json'\n data: T\n },\n ApiCallResultSchema\n>\n\nexport const isApiCallJsonResult = <T extends ApiCallJsonResultType = ApiCallJsonResultType>(x?: unknown | null): x is ApiCallJsonResult<T> => {\n return isPayloadOfSchemaType(ApiCallResultSchema)(x) && (x as ApiCallJsonResult)?.contentType === 'application/json'\n}\nexport const asApiCallJsonResult = AsObjectFactory.create(isApiCallJsonResult)\n\nexport type ApiCallBase64Result = Payload<\n {\n call: Hash\n contentType: Exclude<string, ApiCallJsonResult['contentType']>\n data: string\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallErrorResult = Payload<\n {\n call: Hash\n http?: HttpMeta\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallResult<TJson extends JsonArray | JsonObject = JsonArray | JsonObject> =\n | ApiCallBase64Result\n | ApiCallJsonResult<TJson>\n | ApiCallErrorResult\n\nexport const isApiCallResult = isPayloadOfSchemaType<ApiCallResult>(ApiCallResultSchema)\nexport const asApiCallResult = AsObjectFactory.create(isApiCallResult)\n","import { assertEx } from '@xylabs/assert'\nimport { Axios, AxiosError, AxiosJson } from '@xylabs/axios'\nimport { Hash } from '@xylabs/hex'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessParams } from '@xyo-network/witness-model'\nimport { fromByteArray } from 'base64-js'\nimport template from 'es6-template-strings'\n\nimport { ApiCallWitnessConfig, ApiCallWitnessConfigSchema, asApiUriCallWitnessConfig, asApiUriTemplateCallWitnessConfig } from './Config'\nimport { checkIpfsUrl } from './lib'\nimport {\n ApiCall,\n ApiCallBase64Result,\n ApiCallErrorResult,\n ApiCallJsonResult,\n ApiCallJsonResultType,\n ApiCallResult,\n ApiCallResultSchema,\n ApiCallSchema,\n asApiUriCall,\n asApiUriTemplateCall,\n} from './Payload'\n\nexport type ApiCallWitnessParams = WitnessParams<\n ApiCallWitnessConfig,\n {\n headers?: Record<string, string | undefined>\n ipfsGateway?: string\n }\n>\n\nexport class ApiCallWitness<TParams extends ApiCallWitnessParams = ApiCallWitnessParams> extends AbstractWitness<TParams, ApiCall, ApiCallResult> {\n static override configSchemas = [ApiCallWitnessConfigSchema]\n\n get accept() {\n return this.config.accept ?? 'application/json'\n }\n\n get ipfsGateway() {\n return this.params.ipfsGateway\n }\n\n get timeout() {\n return this.config.timeout\n }\n\n getFullUri(call?: ApiCall): string {\n const { uri: callUri } = asApiUriCall(call) ?? {}\n const { uriTemplate: callUriTemplate, params: callParams, queries: callQueries } = asApiUriTemplateCall(call) ?? {}\n const { uri: configUri } = asApiUriCallWitnessConfig(this.config) ?? {}\n const { uriTemplate: configUriTemplate, params: configParams, queries: configQueries } = asApiUriTemplateCallWitnessConfig(this.config) ?? {}\n\n const params = { ...configParams, ...callParams }\n\n let url: URL | undefined = undefined\n\n if (callUri) {\n url = new URL(callUri)\n } else if (callUriTemplate) {\n url = new URL(template(callUriTemplate, params))\n } else if (configUri) {\n url = new URL(configUri)\n } else if (configUriTemplate) {\n url = new URL(template(configUriTemplate, params))\n }\n\n if (url) {\n const queries = Object.entries({ ...configQueries, ...callQueries })\n queries.map(([key, value]) => url?.searchParams.set(key, value))\n return url.href\n }\n\n throw new Error('Unable to determine uri. No uri/uriTemplate specified in either the call or config.')\n }\n\n protected override async observeHandler(inPayloads: ApiCall[] = []): Promise<ApiCallResult[]> {\n await this.started('throw')\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType(ApiCallSchema)).map(async (call) => {\n const { verb: callVerb } = call\n const { verb: configVerb } = this.config\n const verb = callVerb ?? configVerb ?? 'get'\n const uri = this.getFullUri(call)\n\n const validatedUri = assertEx(checkIpfsUrl(uri, this.ipfsGateway), 'Invalid URI')\n\n if (verb === 'get') {\n return this.httpGet(validatedUri, uri)\n }\n\n const observation: ApiCallResult = {\n call: await PayloadHasher.hash(call),\n schema: ApiCallResultSchema,\n }\n return observation\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.error(`Error [${this.config.name}]: ${error.message}`)\n console.log(error.stack)\n throw error\n }\n }\n\n private async httpGet(url: string, call: Hash): Promise<ApiCallResult> {\n const result: ApiCallResult = {\n call,\n schema: ApiCallResultSchema,\n }\n try {\n switch (this.accept) {\n case 'application/json': {\n const axios = new AxiosJson({ headers: this.params.headers, timeout: this.timeout })\n const response = await axios.get<ApiCallJsonResultType>(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallJsonResult\n jsonResult.data = response.data\n jsonResult.contentType = 'application/json'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n default: {\n const axios = new Axios({ headers: this.params.headers, responseType: 'arraybuffer', timeout: this.timeout })\n const response = await axios.get(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallBase64Result\n jsonResult.data = fromByteArray(Buffer.from(response.data, 'binary'))\n jsonResult.contentType = response.headers['content-type']?.toString() ?? 'application/octet-stream'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n }\n } catch (ex) {\n const axiosError = ex as AxiosError\n if (axiosError.isAxiosError) {\n if (axiosError?.response?.status !== undefined) {\n result.http = result.http ?? {}\n result.http.status = axiosError?.response?.status\n }\n if (axiosError?.code !== undefined) {\n result.http = result.http ?? {}\n result.http.code = axiosError?.code\n }\n return result\n } else {\n throw ex\n }\n }\n return result\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nconst allowIpfsIoRepair = true\n\n/**\n * Returns the equivalent IPFS gateway URL for the supplied URL.\n * @param urlToCheck The URL to check\n * @returns If the supplied URL is an IPFS URL, it converts the URL to the\n * equivalent IPFS gateway URL. Otherwise, returns the original URL.\n */\nexport const checkIpfsUrl = (urlToCheck: string, ipfsGateway?: string): string => {\n try {\n const url = new URL(urlToCheck)\n let protocol = url.protocol\n let host = url.host\n let path = url.pathname\n const query = url.search\n if (protocol === 'ipfs:') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else if (allowIpfsIoRepair && protocol === 'https' && host === 'ipfs.io') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n const pathParts = path.split('/')\n if (pathParts[0] === 'ipfs') {\n pathParts.shift()\n }\n path = pathParts.join('/')\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else {\n return urlToCheck\n }\n } catch {\n //const error = ex as Error\n //console.error(`${error.name}:${error.message} [${urlToCheck}]`)\n //console.log(error.stack)\n return urlToCheck\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAgC;AAChC,2BAAsC;AAK/B,IAAM,6BAA6B;AA0BnC,IAAM,6BAAyB,4CAA4C,0BAA0B;AACrG,IAAM,yBAAyB,8BAAgB,OAAO,sBAAsB;AAE5E,IAAM,4BAA4B,CAAC,UACxC,uBAAuB,KAAK,KAAK,CAAC,CAAE,MAAkC;AACjE,IAAM,4BAA4B,8BAAgB,OAAO,yBAAyB;AAElF,IAAM,oCAAoC,CAAC,UAChD,uBAAuB,KAAK,KA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,CAAC;AAC9B,iBAAO,KAAK,UAAS,8CAAY,aAAZ,mBAAsB;AAAA,QAC7C;AACA,aAAI,yCAAY,UAAS,QAAW;AAClC,iBAAO,OAAO,OAAO,QAAQ,CAAC;AAC9B,iBAAO,KAAK,OAAO,yCAAY;AAAA,QACjC;AACA,eAAO;AAAA,MACT,OAAO;AACL,cAAM;AAAA,MACR;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["import_object","import_payload_model","import_assert","import_payload_model","template"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Config.ts","../../src/Payload.ts","../../src/Witness.ts","../../src/lib/checkIpfsUrl.ts"],"sourcesContent":["export * from './Config'\nexport * from './Payload'\nexport * from './Witness'\n","import { AsObjectFactory } from '@xylabs/object'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessConfig } from '@xyo-network/witness-model'\n\nimport { ApiCall, ApiUriCall, ApiUriTemplateCall } from './Payload'\n\nexport const ApiCallWitnessConfigSchema = 'network.xyo.api.call.witness.config'\nexport type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema\n\nexport type ApiCallWitnessConfigBase = WitnessConfig<{\n accept?: 'application/json'\n queries?: ApiCall['queries']\n schema: ApiCallWitnessConfigSchema\n timeout?: number\n verb?: ApiCall['verb']\n}>\n\nexport type ApiUriCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n uri: ApiUriCall['uri']\n }\n>\n\nexport type ApiUriTemplateCallWitnessConfig = WitnessConfig<\n ApiCallWitnessConfigBase & {\n params?: Record<string, unknown>\n uriTemplate: ApiUriTemplateCall['uriTemplate']\n }\n>\n\nexport type ApiCallWitnessConfig = ApiUriCallWitnessConfig | ApiUriTemplateCallWitnessConfig | ApiCallWitnessConfigBase\n\nexport const isApiCallWitnessConfig = isPayloadOfSchemaType<ApiCallWitnessConfig>(ApiCallWitnessConfigSchema)\nexport const asApiCallWitnessConfig = AsObjectFactory.create(isApiCallWitnessConfig)\n\nexport const isApiUriCallWitnessConfig = (value?: unknown): value is ApiUriCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriCallWitnessConfig).uri\nexport const asApiUriCallWitnessConfig = AsObjectFactory.create(isApiUriCallWitnessConfig)\n\nexport const isApiUriTemplateCallWitnessConfig = (value?: unknown): value is ApiUriTemplateCallWitnessConfig =>\n isApiCallWitnessConfig(value) && !!(value as ApiUriTemplateCallWitnessConfig).uriTemplate\nexport const asApiUriTemplateCallWitnessConfig = AsObjectFactory.create(isApiUriTemplateCallWitnessConfig)\n","import { Hash } from '@xylabs/hex'\nimport { AsObjectFactory, JsonArray, JsonObject } from '@xylabs/object'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\nexport const ApiCallSchema = 'network.xyo.api.call'\nexport type ApiCallSchema = typeof ApiCallSchema\n\nexport type Verb = 'get' | 'post'\nexport type Queries = Record<string, string>\n\nexport interface ApiCallFields {\n queries?: Queries\n verb?: Verb\n}\n\nexport type ApiUriCall = Payload<\n ApiCallFields & {\n uri: string\n },\n ApiCallSchema\n>\nexport const isApiUriCall = (value?: unknown): value is ApiUriCall => isApiCall(value) && !!(value as ApiUriCall).uri\nexport const asApiUriCall = AsObjectFactory.create(isApiUriCall)\n\nexport type ApiUriTemplateCall = Payload<\n ApiCallFields & {\n params?: Record<string, unknown>\n uriTemplate?: string\n },\n ApiCallSchema\n>\nexport const isApiUriTemplateCall = (value?: unknown): value is ApiUriTemplateCall =>\n isApiCall(value) && !!((value as ApiUriTemplateCall).uriTemplate || (value as ApiUriTemplateCall).params)\nexport const asApiUriTemplateCall = AsObjectFactory.create(isApiUriTemplateCall)\n\nexport type ApiCall = ApiUriCall | ApiUriTemplateCall\n\nexport const ApiCallResultSchema = 'network.xyo.api.call.result'\nexport type ApiCallResultSchema = typeof ApiCallResultSchema\n\nexport const isApiCall = isPayloadOfSchemaType<ApiCall>(ApiCallSchema)\nexport const asApiCall = AsObjectFactory.create(isApiCall)\n\nexport interface HttpMeta {\n code?: string\n status?: number\n}\n\nexport type ApiCallJsonResultType = JsonArray | JsonObject\n\nexport type ApiCallJsonResult<T extends ApiCallJsonResultType = ApiCallJsonResultType> = Payload<\n {\n call: Hash\n contentType: 'application/json'\n data: T\n },\n ApiCallResultSchema\n>\n\nexport const isApiCallJsonResult = <T extends ApiCallJsonResultType = ApiCallJsonResultType>(x?: unknown | null): x is ApiCallJsonResult<T> => {\n return isPayloadOfSchemaType(ApiCallResultSchema)(x) && (x as ApiCallJsonResult)?.contentType === 'application/json'\n}\nexport const asApiCallJsonResult = AsObjectFactory.create(isApiCallJsonResult)\n\nexport type ApiCallBase64Result = Payload<\n {\n call: Hash\n contentType: Exclude<string, ApiCallJsonResult['contentType']>\n data: string\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallErrorResult = Payload<\n {\n call: Hash\n http?: HttpMeta\n },\n ApiCallResultSchema\n>\n\nexport type ApiCallResult<TJson extends JsonArray | JsonObject = JsonArray | JsonObject> =\n | ApiCallBase64Result\n | ApiCallJsonResult<TJson>\n | ApiCallErrorResult\n\nexport const isApiCallResult = isPayloadOfSchemaType<ApiCallResult>(ApiCallResultSchema)\nexport const asApiCallResult = AsObjectFactory.create(isApiCallResult)\n","import { assertEx } from '@xylabs/assert'\nimport { Axios, AxiosError, AxiosJson } from '@xylabs/axios'\nimport { Hash } from '@xylabs/hex'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessParams } from '@xyo-network/witness-model'\nimport { fromByteArray } from 'base64-js'\nimport template from 'es6-template-strings'\n\nimport { ApiCallWitnessConfig, ApiCallWitnessConfigSchema, asApiUriCallWitnessConfig, asApiUriTemplateCallWitnessConfig } from './Config'\nimport { checkIpfsUrl } from './lib'\nimport {\n ApiCall,\n ApiCallBase64Result,\n ApiCallErrorResult,\n ApiCallJsonResult,\n ApiCallJsonResultType,\n ApiCallResult,\n ApiCallResultSchema,\n ApiCallSchema,\n asApiUriCall,\n asApiUriTemplateCall,\n} from './Payload'\n\nexport type ApiCallWitnessParams = WitnessParams<\n ApiCallWitnessConfig,\n {\n headers?: Record<string, string | undefined>\n ipfsGateway?: string\n }\n>\n\nexport class ApiCallWitness<TParams extends ApiCallWitnessParams = ApiCallWitnessParams> extends AbstractWitness<TParams, ApiCall, ApiCallResult> {\n static override configSchemas = [ApiCallWitnessConfigSchema]\n\n get accept() {\n return this.config.accept ?? 'application/json'\n }\n\n get ipfsGateway() {\n return this.params.ipfsGateway\n }\n\n get timeout() {\n return this.config.timeout\n }\n\n getFullUri(call?: ApiCall): string {\n const { uri: callUri } = asApiUriCall(call) ?? {}\n const { uriTemplate: callUriTemplate, params: callParams, queries: callQueries } = asApiUriTemplateCall(call) ?? {}\n const { uri: configUri } = asApiUriCallWitnessConfig(this.config) ?? {}\n const { uriTemplate: configUriTemplate, params: configParams, queries: configQueries } = asApiUriTemplateCallWitnessConfig(this.config) ?? {}\n\n const params = { ...configParams, ...callParams }\n\n let url: URL | undefined = undefined\n\n if (callUri) {\n url = new URL(callUri)\n } else if (callUriTemplate) {\n url = new URL(template(callUriTemplate, params))\n } else if (configUri) {\n url = new URL(configUri)\n } else if (configUriTemplate) {\n url = new URL(template(configUriTemplate, params))\n }\n\n if (url) {\n const queries = Object.entries({ ...configQueries, ...callQueries })\n queries.map(([key, value]) => url?.searchParams.set(key, value))\n return url.href\n }\n\n throw new Error('Unable to determine uri. No uri/uriTemplate specified in either the call or config.')\n }\n\n protected override async observeHandler(inPayloads: ApiCall[] = []): Promise<ApiCallResult[]> {\n await this.started('throw')\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType(ApiCallSchema)).map(async (call) => {\n const { verb: callVerb } = call\n const { verb: configVerb } = this.config\n const verb = callVerb ?? configVerb ?? 'get'\n const uri = this.getFullUri(call)\n\n const validatedUri = assertEx(checkIpfsUrl(uri, this.ipfsGateway), 'Invalid URI')\n\n if (verb === 'get') {\n return this.httpGet(validatedUri, (await PayloadBuilder.build(call)).$hash)\n }\n\n const observation: ApiCallResult = {\n call: await PayloadHasher.hash(call),\n schema: ApiCallResultSchema,\n }\n return observation\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.error(`Error [${this.config.name}]: ${error.message}`)\n console.log(error.stack)\n throw error\n }\n }\n\n private async httpGet(url: string, call: Hash): Promise<ApiCallResult> {\n const result: ApiCallResult = {\n call,\n schema: ApiCallResultSchema,\n }\n try {\n switch (this.accept) {\n case 'application/json': {\n const axios = new AxiosJson({ headers: this.params.headers, timeout: this.timeout })\n const response = await axios.get<ApiCallJsonResultType>(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallJsonResult\n jsonResult.data = response.data\n jsonResult.contentType = 'application/json'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n default: {\n const axios = new Axios({ headers: this.params.headers, responseType: 'arraybuffer', timeout: this.timeout })\n const response = await axios.get(url)\n if (response.status >= 200 && response.status < 300) {\n const jsonResult = result as ApiCallBase64Result\n jsonResult.data = fromByteArray(Buffer.from(response.data, 'binary'))\n jsonResult.contentType = response.headers['content-type']?.toString() ?? 'application/octet-stream'\n } else {\n const errorResult = result as ApiCallErrorResult\n errorResult.http = {\n status: response.status,\n }\n }\n break\n }\n }\n } catch (ex) {\n const axiosError = ex as AxiosError\n if (axiosError.isAxiosError) {\n if (axiosError?.response?.status !== undefined) {\n result.http = result.http ?? {}\n result.http.status = axiosError?.response?.status\n }\n if (axiosError?.code !== undefined) {\n result.http = result.http ?? {}\n result.http.code = axiosError?.code\n }\n return result\n } else {\n throw ex\n }\n }\n return result\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nconst allowIpfsIoRepair = true\n\n/**\n * Returns the equivalent IPFS gateway URL for the supplied URL.\n * @param urlToCheck The URL to check\n * @returns If the supplied URL is an IPFS URL, it converts the URL to the\n * equivalent IPFS gateway URL. Otherwise, returns the original URL.\n */\nexport const checkIpfsUrl = (urlToCheck: string, ipfsGateway?: string): string => {\n try {\n const url = new URL(urlToCheck)\n let protocol = url.protocol\n let host = url.host\n let path = url.pathname\n const query = url.search\n if (protocol === 'ipfs:') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else if (allowIpfsIoRepair && protocol === 'https' && host === 'ipfs.io') {\n protocol = 'https:'\n host = assertEx(ipfsGateway, 'No ipfsGateway provided')\n const pathParts = path.split('/')\n if (pathParts[0] === 'ipfs') {\n pathParts.shift()\n }\n path = pathParts.join('/')\n const root = `${protocol}//${host}/${path}`\n return query?.length > 0 ? `${root}?${query}` : root\n } else {\n return urlToCheck\n }\n } catch {\n //const error = ex as Error\n //console.error(`${error.name}:${error.message} [${urlToCheck}]`)\n //console.log(error.stack)\n return urlToCheck\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAgC;AAChC,2BAAsC;AAK/B,IAAM,6BAA6B;AA0BnC,IAAM,6BAAyB,4CAA4C,0BAA0B;AACrG,IAAM,yBAAyB,8BAAgB,OAAO,sBAAsB;AAE5E,IAAM,4BAA4B,CAAC,UACxC,uBAAuB,KAAK,KAAK,CAAC,CAAE,MAAkC;AACjE,IAAM,4BAA4B,8BAAgB,OAAO,yBAAyB;AAElF,IAAM,oCAAoC,CAAC,UAChD,uBAAuB,KAAK,KAAK,CAAC,CAAE,MAA0C;AACzE,IAAM,oCAAoC,8B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