@xyo-network/api-call-witness 2.79.5

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.
Files changed (77) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/Payload.d.cts +31 -0
  4. package/dist/browser/Payload.d.cts.map +1 -0
  5. package/dist/browser/Payload.d.mts +31 -0
  6. package/dist/browser/Payload.d.mts.map +1 -0
  7. package/dist/browser/Payload.d.ts +31 -0
  8. package/dist/browser/Payload.d.ts.map +1 -0
  9. package/dist/browser/Witness.d.cts +21 -0
  10. package/dist/browser/Witness.d.cts.map +1 -0
  11. package/dist/browser/Witness.d.mts +21 -0
  12. package/dist/browser/Witness.d.mts.map +1 -0
  13. package/dist/browser/Witness.d.ts +21 -0
  14. package/dist/browser/Witness.d.ts.map +1 -0
  15. package/dist/browser/index.cjs +160 -0
  16. package/dist/browser/index.cjs.map +1 -0
  17. package/dist/browser/index.d.cts +3 -0
  18. package/dist/browser/index.d.cts.map +1 -0
  19. package/dist/browser/index.d.mts +3 -0
  20. package/dist/browser/index.d.mts.map +1 -0
  21. package/dist/browser/index.d.ts +3 -0
  22. package/dist/browser/index.d.ts.map +1 -0
  23. package/dist/browser/index.js +137 -0
  24. package/dist/browser/index.js.map +1 -0
  25. package/dist/browser/lib/checkIpfsUrl.d.cts +8 -0
  26. package/dist/browser/lib/checkIpfsUrl.d.cts.map +1 -0
  27. package/dist/browser/lib/checkIpfsUrl.d.mts +8 -0
  28. package/dist/browser/lib/checkIpfsUrl.d.mts.map +1 -0
  29. package/dist/browser/lib/checkIpfsUrl.d.ts +8 -0
  30. package/dist/browser/lib/checkIpfsUrl.d.ts.map +1 -0
  31. package/dist/browser/lib/index.d.cts +2 -0
  32. package/dist/browser/lib/index.d.cts.map +1 -0
  33. package/dist/browser/lib/index.d.mts +2 -0
  34. package/dist/browser/lib/index.d.mts.map +1 -0
  35. package/dist/browser/lib/index.d.ts +2 -0
  36. package/dist/browser/lib/index.d.ts.map +1 -0
  37. package/dist/node/Payload.d.cts +31 -0
  38. package/dist/node/Payload.d.cts.map +1 -0
  39. package/dist/node/Payload.d.mts +31 -0
  40. package/dist/node/Payload.d.mts.map +1 -0
  41. package/dist/node/Payload.d.ts +31 -0
  42. package/dist/node/Payload.d.ts.map +1 -0
  43. package/dist/node/Witness.d.cts +21 -0
  44. package/dist/node/Witness.d.cts.map +1 -0
  45. package/dist/node/Witness.d.mts +21 -0
  46. package/dist/node/Witness.d.mts.map +1 -0
  47. package/dist/node/Witness.d.ts +21 -0
  48. package/dist/node/Witness.d.ts.map +1 -0
  49. package/dist/node/index.cjs +168 -0
  50. package/dist/node/index.cjs.map +1 -0
  51. package/dist/node/index.d.cts +3 -0
  52. package/dist/node/index.d.cts.map +1 -0
  53. package/dist/node/index.d.mts +3 -0
  54. package/dist/node/index.d.mts.map +1 -0
  55. package/dist/node/index.d.ts +3 -0
  56. package/dist/node/index.d.ts.map +1 -0
  57. package/dist/node/index.js +138 -0
  58. package/dist/node/index.js.map +1 -0
  59. package/dist/node/lib/checkIpfsUrl.d.cts +8 -0
  60. package/dist/node/lib/checkIpfsUrl.d.cts.map +1 -0
  61. package/dist/node/lib/checkIpfsUrl.d.mts +8 -0
  62. package/dist/node/lib/checkIpfsUrl.d.mts.map +1 -0
  63. package/dist/node/lib/checkIpfsUrl.d.ts +8 -0
  64. package/dist/node/lib/checkIpfsUrl.d.ts.map +1 -0
  65. package/dist/node/lib/index.d.cts +2 -0
  66. package/dist/node/lib/index.d.cts.map +1 -0
  67. package/dist/node/lib/index.d.mts +2 -0
  68. package/dist/node/lib/index.d.mts.map +1 -0
  69. package/dist/node/lib/index.d.ts +2 -0
  70. package/dist/node/lib/index.d.ts.map +1 -0
  71. package/package.json +72 -0
  72. package/src/Payload.ts +51 -0
  73. package/src/Witness.ts +129 -0
  74. package/src/index.ts +2 -0
  75. package/src/lib/checkIpfsUrl.ts +31 -0
  76. package/src/lib/index.ts +1 -0
  77. package/typedoc.json +5 -0
@@ -0,0 +1,137 @@
1
+ // src/Payload.ts
2
+ var ApiCallSchema = "network.xyo.api.call";
3
+ var ApiCallResultSchema = "network.xyo.api.call.result";
4
+
5
+ // src/Witness.ts
6
+ import { assertEx as assertEx2 } from "@xylabs/assert";
7
+ import { Axios, AxiosJson } from "@xylabs/axios";
8
+ import { Buffer } from "@xylabs/buffer";
9
+ import { AbstractWitness } from "@xyo-network/abstract-witness";
10
+ import { PayloadHasher } from "@xyo-network/hash";
11
+ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
12
+ import { fromByteArray } from "base64-js";
13
+
14
+ // src/lib/checkIpfsUrl.ts
15
+ import { assertEx } from "@xylabs/assert";
16
+ var checkIpfsUrl = (urlToCheck, ipfsGateway) => {
17
+ try {
18
+ const url = new URL(urlToCheck);
19
+ let protocol = url.protocol;
20
+ let host = url.host;
21
+ let path = url.pathname;
22
+ const query = url.search;
23
+ if (protocol === "ipfs:") {
24
+ protocol = "https:";
25
+ host = assertEx(ipfsGateway, "No ipfsGateway provided");
26
+ path = url.host === "ipfs" ? `ipfs${path}` : `ipfs/${url.host}${path}`;
27
+ const root = `${protocol}//${host}/${path}`;
28
+ return query?.length > 0 ? `${root}?${query}` : root;
29
+ } else {
30
+ return urlToCheck;
31
+ }
32
+ } catch (ex) {
33
+ const error = ex;
34
+ console.error(`${error.name}:${error.message} [${urlToCheck}]`);
35
+ console.log(error.stack);
36
+ return void 0;
37
+ }
38
+ };
39
+
40
+ // src/Witness.ts
41
+ var ApiCallWitnessConfigSchema = "network.xyo.api.call.witness.config";
42
+ var ApiCallWitness = class extends AbstractWitness {
43
+ static configSchemas = [ApiCallWitnessConfigSchema];
44
+ get accept() {
45
+ return this.config.accept;
46
+ }
47
+ get ipfsGateway() {
48
+ return this.params.ipfsGateway;
49
+ }
50
+ async observeHandler(inPayloads = []) {
51
+ await this.started("throw");
52
+ try {
53
+ const observations = await Promise.all(
54
+ inPayloads.filter(isPayloadOfSchemaType(ApiCallSchema)).map(async (call) => {
55
+ const { uri, verb } = call;
56
+ const validatedUri = assertEx2(checkIpfsUrl(uri, this.ipfsGateway), "Invalid URI");
57
+ if (verb === "get") {
58
+ return this.httpGet(validatedUri, uri);
59
+ }
60
+ const observation = {
61
+ call: await PayloadHasher.hashAsync(call),
62
+ schema: ApiCallResultSchema
63
+ };
64
+ return observation;
65
+ })
66
+ );
67
+ return observations;
68
+ } catch (ex) {
69
+ const error = ex;
70
+ console.log(`Error [${this.config.name}]: ${error.message}`);
71
+ throw error;
72
+ }
73
+ }
74
+ async httpGet(url, call) {
75
+ const result = {
76
+ call,
77
+ schema: ApiCallResultSchema
78
+ };
79
+ try {
80
+ switch (this.accept) {
81
+ case "application/json": {
82
+ const axios = new AxiosJson();
83
+ const response = await axios.get(url);
84
+ if (response.status >= 200 && response.status < 300) {
85
+ const jsonResult = result;
86
+ jsonResult.data = response.data;
87
+ jsonResult.contentType = "application/json";
88
+ } else {
89
+ const errorResult = result;
90
+ errorResult.http = {
91
+ status: response.status
92
+ };
93
+ }
94
+ break;
95
+ }
96
+ default: {
97
+ const axios = new Axios({ responseType: "arraybuffer" });
98
+ const response = await axios.get(url);
99
+ if (response.status >= 200 && response.status < 300) {
100
+ const jsonResult = result;
101
+ jsonResult.data = fromByteArray(Buffer.from(response.data, "binary"));
102
+ jsonResult.contentType = response.headers["content-type"]?.toString() ?? "application/octet-stream";
103
+ } else {
104
+ const errorResult = result;
105
+ errorResult.http = {
106
+ status: response.status
107
+ };
108
+ }
109
+ break;
110
+ }
111
+ }
112
+ } catch (ex) {
113
+ const axiosError = ex;
114
+ if (axiosError.isAxiosError) {
115
+ if (axiosError?.response?.status !== void 0) {
116
+ result.http = result.http ?? {};
117
+ result.http.status = axiosError?.response?.status;
118
+ }
119
+ if (axiosError?.code !== void 0) {
120
+ result.http = result.http ?? {};
121
+ result.http.code = axiosError?.code;
122
+ }
123
+ return result;
124
+ } else {
125
+ throw ex;
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+ };
131
+ export {
132
+ ApiCallResultSchema,
133
+ ApiCallSchema,
134
+ ApiCallWitness,
135
+ ApiCallWitnessConfigSchema
136
+ };
137
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Payload.ts","../../src/Witness.ts","../../src/lib/checkIpfsUrl.ts"],"sourcesContent":["import { Hash } from '@xyo-network/hash'\nimport { 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'\n\nexport type ApiCall = Payload<\n {\n uri: string\n verb?: Verb\n },\n ApiCallSchema\n>\n\nexport const ApiCallResultSchema = 'network.xyo.api.call.result'\nexport type ApiCallResultSchema = typeof ApiCallResultSchema\n\nexport interface HttpMeta {\n code?: string\n status?: number\n}\n\nexport type ApiCallJsonResult<T extends object | [] = object> = Payload<\n {\n call: Hash\n contentType: 'application/json'\n data: T\n },\n ApiCallResultSchema\n>\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 = ApiCallBase64Result | ApiCallJsonResult | ApiCallErrorResult\n","import { assertEx } from '@xylabs/assert'\nimport { Axios, AxiosError, AxiosJson } from '@xylabs/axios'\nimport { Buffer } from '@xylabs/buffer'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { Hash, PayloadHasher } from '@xyo-network/hash'\nimport { JsonArray, JsonObject } from '@xyo-network/object'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { fromByteArray } from 'base64-js'\n\nimport { checkIpfsUrl } from './lib'\nimport {\n ApiCall,\n ApiCallBase64Result,\n ApiCallErrorResult,\n ApiCallJsonResult,\n ApiCallResult,\n ApiCallResultSchema,\n ApiCallSchema,\n Verb,\n} from './Payload'\n\nexport const ApiCallWitnessConfigSchema = 'network.xyo.api.call.witness.config'\nexport type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema\n\nexport type ApiCallWitnessConfig = WitnessConfig<{\n accept: 'application/json'\n schema: ApiCallWitnessConfigSchema\n verb?: Verb\n}>\n\nexport type ApiCallWitnessParams = WitnessParams<ApiCallWitnessConfig, { ipfsGateway?: string }>\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\n }\n\n get ipfsGateway() {\n return this.params.ipfsGateway\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 { uri, verb } = 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.hashAsync(call),\n schema: ApiCallResultSchema,\n }\n return observation\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.log(`Error [${this.config.name}]: ${error.message}`)\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()\n const response = await axios.get<JsonArray | JsonObject>(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({ responseType: 'arraybuffer' })\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\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) => {\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 {\n return urlToCheck\n }\n } catch (ex) {\n const error = ex as Error\n console.error(`${error.name}:${error.message} [${urlToCheck}]`)\n console.log(error.stack)\n return undefined\n }\n}\n"],"mappings":";AAGO,IAAM,gBAAgB;AAatB,IAAM,sBAAsB;;;AChBnC,SAAS,YAAAA,iBAAgB;AACzB,SAAS,OAAmB,iBAAiB;AAC7C,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAChC,SAAe,qBAAqB;AAEpC,SAAS,6BAA6B;AAE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;AAAA,QACF;AAAA,MACF;AAAA,IACF,SAAS,IAAI;AACX,YAAM,aAAa;AACnB,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":["assertEx","assertEx"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the equivalent IPFS gateway URL for the supplied URL.
3
+ * @param urlToCheck The URL to check
4
+ * @returns If the supplied URL is an IPFS URL, it converts the URL to the
5
+ * equivalent IPFS gateway URL. Otherwise, returns the original URL.
6
+ */
7
+ export declare const checkIpfsUrl: (urlToCheck: string, ipfsGateway?: string) => string | undefined;
8
+ //# sourceMappingURL=checkIpfsUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkIpfsUrl.d.ts","sourceRoot":"","sources":["../../../src/lib/checkIpfsUrl.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,gBAAgB,MAAM,uBAsBpE,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the equivalent IPFS gateway URL for the supplied URL.
3
+ * @param urlToCheck The URL to check
4
+ * @returns If the supplied URL is an IPFS URL, it converts the URL to the
5
+ * equivalent IPFS gateway URL. Otherwise, returns the original URL.
6
+ */
7
+ export declare const checkIpfsUrl: (urlToCheck: string, ipfsGateway?: string) => string | undefined;
8
+ //# sourceMappingURL=checkIpfsUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkIpfsUrl.d.ts","sourceRoot":"","sources":["../../../src/lib/checkIpfsUrl.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,gBAAgB,MAAM,uBAsBpE,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the equivalent IPFS gateway URL for the supplied URL.
3
+ * @param urlToCheck The URL to check
4
+ * @returns If the supplied URL is an IPFS URL, it converts the URL to the
5
+ * equivalent IPFS gateway URL. Otherwise, returns the original URL.
6
+ */
7
+ export declare const checkIpfsUrl: (urlToCheck: string, ipfsGateway?: string) => string | undefined;
8
+ //# sourceMappingURL=checkIpfsUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkIpfsUrl.d.ts","sourceRoot":"","sources":["../../../src/lib/checkIpfsUrl.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,gBAAgB,MAAM,uBAsBpE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './checkIpfsUrl';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './checkIpfsUrl';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './checkIpfsUrl';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { Hash } from '@xyo-network/hash';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ export declare const ApiCallSchema = "network.xyo.api.call";
4
+ export type ApiCallSchema = typeof ApiCallSchema;
5
+ export type Verb = 'get' | 'post';
6
+ export type ApiCall = Payload<{
7
+ uri: string;
8
+ verb?: Verb;
9
+ }, ApiCallSchema>;
10
+ export declare const ApiCallResultSchema = "network.xyo.api.call.result";
11
+ export type ApiCallResultSchema = typeof ApiCallResultSchema;
12
+ export interface HttpMeta {
13
+ code?: string;
14
+ status?: number;
15
+ }
16
+ export type ApiCallJsonResult<T extends object | [] = object> = Payload<{
17
+ call: Hash;
18
+ contentType: 'application/json';
19
+ data: T;
20
+ }, ApiCallResultSchema>;
21
+ export type ApiCallBase64Result = Payload<{
22
+ call: Hash;
23
+ contentType: Exclude<string, ApiCallJsonResult['contentType']>;
24
+ data: string;
25
+ }, ApiCallResultSchema>;
26
+ export type ApiCallErrorResult = Payload<{
27
+ call: Hash;
28
+ http?: HttpMeta;
29
+ }, ApiCallResultSchema>;
30
+ export type ApiCallResult = ApiCallBase64Result | ApiCallJsonResult | ApiCallErrorResult;
31
+ //# sourceMappingURL=Payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,eAAO,MAAM,aAAa,yBAAyB,CAAA;AACnD,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAA;AAEjC,MAAM,MAAM,OAAO,GAAG,OAAO,CAC3B;IACE,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,EACD,aAAa,CACd,CAAA;AAED,eAAO,MAAM,mBAAmB,gCAAgC,CAAA;AAChE,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,EAAE,GAAG,MAAM,IAAI,OAAO,CACrE;IACE,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,kBAAkB,CAAA;IAC/B,IAAI,EAAE,CAAC,CAAA;CACR,EACD,mBAAmB,CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC;IACE,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAA;IAC9D,IAAI,EAAE,MAAM,CAAA;CACb,EACD,mBAAmB,CACpB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC;IACE,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,EACD,mBAAmB,CACpB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,kBAAkB,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { Hash } from '@xyo-network/hash';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ export declare const ApiCallSchema = "network.xyo.api.call";
4
+ export type ApiCallSchema = typeof ApiCallSchema;
5
+ export type Verb = 'get' | 'post';
6
+ export type ApiCall = Payload<{
7
+ uri: string;
8
+ verb?: Verb;
9
+ }, ApiCallSchema>;
10
+ export declare const ApiCallResultSchema = "network.xyo.api.call.result";
11
+ export type ApiCallResultSchema = typeof ApiCallResultSchema;
12
+ export interface HttpMeta {
13
+ code?: string;
14
+ status?: number;
15
+ }
16
+ export type ApiCallJsonResult<T extends object | [] = object> = Payload<{
17
+ call: Hash;
18
+ contentType: 'application/json';
19
+ data: T;
20
+ }, ApiCallResultSchema>;
21
+ export type ApiCallBase64Result = Payload<{
22
+ call: Hash;
23
+ contentType: Exclude<string, ApiCallJsonResult['contentType']>;
24
+ data: string;
25
+ }, ApiCallResultSchema>;
26
+ export type ApiCallErrorResult = Payload<{
27
+ call: Hash;
28
+ http?: HttpMeta;
29
+ }, ApiCallResultSchema>;
30
+ export type ApiCallResult = ApiCallBase64Result | ApiCallJsonResult | ApiCallErrorResult;
31
+ //# sourceMappingURL=Payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,eAAO,MAAM,aAAa,yBAAyB,CAAA;AACnD,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAA;AAEjC,MAAM,MAAM,OAAO,GAAG,OAAO,CAC3B;IACE,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,EACD,aAAa,CACd,CAAA;AAED,eAAO,MAAM,mBAAmB,gCAAgC,CAAA;AAChE,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,EAAE,GAAG,MAAM,IAAI,OAAO,CACrE;IACE,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,kBAAkB,CAAA;IAC/B,IAAI,EAAE,CAAC,CAAA;CACR,EACD,mBAAmB,CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC;IACE,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAA;IAC9D,IAAI,EAAE,MAAM,CAAA;CACb,EACD,mBAAmB,CACpB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC;IACE,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB,EACD,mBAAmB,CACpB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,kBAAkB,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { Hash } from '@xyo-network/hash';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ export declare const ApiCallSchema = "network.xyo.api.call";
4
+ export type ApiCallSchema = typeof ApiCallSchema;
5
+ export type Verb = 'get' | 'post';
6
+ export type ApiCall = Payload<{
7
+ uri: string;
8
+ verb?: Verb;
9
+ }, ApiCallSchema>;
10
+ export declare const ApiCallResultSchema = "network.xyo.api.call.result";
11
+ export type ApiCallResultSchema = typeof ApiCallResultSchema;
12
+ export interface HttpMeta {
13
+ code?: string;
14
+ status?: number;
15
+ }
16
+ export type ApiCallJsonResult<T extends object | [] = object> = Payload<{
17
+ call: Hash;
18
+ contentType: 'application/json';
19
+ data: T;
20
+ }, ApiCallResultSchema>;
21
+ export type ApiCallBase64Result = Payload<{
22
+ call: Hash;
23
+ contentType: Exclude<string, ApiCallJsonResult['contentType']>;
24
+ data: string;
25
+ }, ApiCallResultSchema>;
26
+ export type ApiCallErrorResult = Payload<{
27
+ call: Hash;
28
+ http?: HttpMeta;
29
+ }, ApiCallResultSchema>;
30
+ export type ApiCallResult = ApiCallBase64Result | ApiCallJsonResult | ApiCallErrorResult;
31
+ //# sourceMappingURL=Payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mB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';
2
+ import { WitnessConfig, WitnessParams } from '@xyo-network/witness-model';
3
+ import { ApiCall, ApiCallResult, Verb } from './Payload';
4
+ export declare const ApiCallWitnessConfigSchema = "network.xyo.api.call.witness.config";
5
+ export type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema;
6
+ export type ApiCallWitnessConfig = WitnessConfig<{
7
+ accept: 'application/json';
8
+ schema: ApiCallWitnessConfigSchema;
9
+ verb?: Verb;
10
+ }>;
11
+ export type ApiCallWitnessParams = WitnessParams<ApiCallWitnessConfig, {
12
+ ipfsGateway?: string;
13
+ }>;
14
+ export declare class ApiCallWitness<TParams extends ApiCallWitnessParams = ApiCallWitnessParams> extends AbstractWitness<TParams, ApiCall, ApiCallResult> {
15
+ static configSchemas: string[];
16
+ get accept(): "application/json";
17
+ get ipfsGateway(): string | undefined;
18
+ protected observeHandler(inPayloads?: ApiCall[]): Promise<ApiCallResult[]>;
19
+ private httpGet;
20
+ }
21
+ //# sourceMappingURL=Witness.d.ts.map
@@ -0,0 +1 @@
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,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAIzE,OAAO,EACL,OAAO,EAIP,aAAa,EAGb,IAAI,EACL,MAAM,WAAW,CAAA;AAElB,eAAO,MAAM,0BAA0B,wCAAwC,CAAA;AAC/E,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAA;AAE1E,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC;IAC/C,MAAM,EAAE,kBAAkB,CAAA;IAC1B,MAAM,EAAE,0BAA0B,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC,oBAAoB,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEhG,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;cAEwB,cAAc,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YA4B/E,OAAO;CAwDtB"}
@@ -0,0 +1,21 @@
1
+ import { AbstractWitness } from '@xyo-network/abstract-witness';
2
+ import { WitnessConfig, WitnessParams } from '@xyo-network/witness-model';
3
+ import { ApiCall, ApiCallResult, Verb } from './Payload';
4
+ export declare const ApiCallWitnessConfigSchema = "network.xyo.api.call.witness.config";
5
+ export type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema;
6
+ export type ApiCallWitnessConfig = WitnessConfig<{
7
+ accept: 'application/json';
8
+ schema: ApiCallWitnessConfigSchema;
9
+ verb?: Verb;
10
+ }>;
11
+ export type ApiCallWitnessParams = WitnessParams<ApiCallWitnessConfig, {
12
+ ipfsGateway?: string;
13
+ }>;
14
+ export declare class ApiCallWitness<TParams extends ApiCallWitnessParams = ApiCallWitnessParams> extends AbstractWitness<TParams, ApiCall, ApiCallResult> {
15
+ static configSchemas: string[];
16
+ get accept(): "application/json";
17
+ get ipfsGateway(): string | undefined;
18
+ protected observeHandler(inPayloads?: ApiCall[]): Promise<ApiCallResult[]>;
19
+ private httpGet;
20
+ }
21
+ //# sourceMappingURL=Witness.d.ts.map
@@ -0,0 +1 @@
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,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAIzE,OAAO,EACL,OAAO,EAIP,aAAa,EAGb,IAAI,EACL,MAAM,WAAW,CAAA;AAElB,eAAO,MAAM,0BAA0B,wCAAwC,CAAA;AAC/E,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAA;AAE1E,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC;IAC/C,MAAM,EAAE,kBAAkB,CAAA;IAC1B,MAAM,EAAE,0BAA0B,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC,oBAAoB,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEhG,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;cAEwB,cAAc,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YA4B/E,OAAO;CAwDtB"}
@@ -0,0 +1,21 @@
1
+ import { AbstractWitness } from '@xyo-network/abstract-witness';
2
+ import { WitnessConfig, WitnessParams } from '@xyo-network/witness-model';
3
+ import { ApiCall, ApiCallResult, Verb } from './Payload';
4
+ export declare const ApiCallWitnessConfigSchema = "network.xyo.api.call.witness.config";
5
+ export type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema;
6
+ export type ApiCallWitnessConfig = WitnessConfig<{
7
+ accept: 'application/json';
8
+ schema: ApiCallWitnessConfigSchema;
9
+ verb?: Verb;
10
+ }>;
11
+ export type ApiCallWitnessParams = WitnessParams<ApiCallWitnessConfig, {
12
+ ipfsGateway?: string;
13
+ }>;
14
+ export declare class ApiCallWitness<TParams extends ApiCallWitnessParams = ApiCallWitnessParams> extends AbstractWitness<TParams, ApiCall, ApiCallResult> {
15
+ static configSchemas: string[];
16
+ get accept(): "application/json";
17
+ get ipfsGateway(): string | undefined;
18
+ protected observeHandler(inPayloads?: ApiCall[]): Promise<ApiCallResult[]>;
19
+ private httpGet;
20
+ }
21
+ //# sourceMappingURL=Witness.d.ts.map
@@ -0,0 +1 @@
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,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAIzE,OAAO,EACL,OAAO,EAIP,aAAa,EAGb,IAAI,EACL,MAAM,WAAW,CAAA;AAElB,eAAO,MAAM,0BAA0B,wCAAwC,CAAA;AAC/E,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAA;AAE1E,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC;IAC/C,MAAM,EAAE,kBAAkB,CAAA;IAC1B,MAAM,EAAE,0BAA0B,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAC,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC,oBAAoB,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEhG,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;cAEwB,cAAc,CAAC,UAAU,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;YA4B/E,OAAO;CAwDtB"}
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ApiCallResultSchema: () => ApiCallResultSchema,
24
+ ApiCallSchema: () => ApiCallSchema,
25
+ ApiCallWitness: () => ApiCallWitness,
26
+ ApiCallWitnessConfigSchema: () => ApiCallWitnessConfigSchema
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/Payload.ts
31
+ var ApiCallSchema = "network.xyo.api.call";
32
+ var ApiCallResultSchema = "network.xyo.api.call.result";
33
+
34
+ // src/Witness.ts
35
+ var import_assert2 = require("@xylabs/assert");
36
+ var import_axios = require("@xylabs/axios");
37
+ var import_buffer = require("@xylabs/buffer");
38
+ var import_abstract_witness = require("@xyo-network/abstract-witness");
39
+ var import_hash = require("@xyo-network/hash");
40
+ var import_payload_model = require("@xyo-network/payload-model");
41
+ var import_base64_js = require("base64-js");
42
+
43
+ // src/lib/checkIpfsUrl.ts
44
+ var import_assert = require("@xylabs/assert");
45
+ var checkIpfsUrl = (urlToCheck, ipfsGateway) => {
46
+ try {
47
+ const url = new URL(urlToCheck);
48
+ let protocol = url.protocol;
49
+ let host = url.host;
50
+ let path = url.pathname;
51
+ const query = url.search;
52
+ if (protocol === "ipfs:") {
53
+ protocol = "https:";
54
+ host = (0, import_assert.assertEx)(ipfsGateway, "No ipfsGateway provided");
55
+ path = url.host === "ipfs" ? `ipfs${path}` : `ipfs/${url.host}${path}`;
56
+ const root = `${protocol}//${host}/${path}`;
57
+ return (query == null ? void 0 : query.length) > 0 ? `${root}?${query}` : root;
58
+ } else {
59
+ return urlToCheck;
60
+ }
61
+ } catch (ex) {
62
+ const error = ex;
63
+ console.error(`${error.name}:${error.message} [${urlToCheck}]`);
64
+ console.log(error.stack);
65
+ return void 0;
66
+ }
67
+ };
68
+
69
+ // src/Witness.ts
70
+ var ApiCallWitnessConfigSchema = "network.xyo.api.call.witness.config";
71
+ var ApiCallWitness = class extends import_abstract_witness.AbstractWitness {
72
+ static configSchemas = [ApiCallWitnessConfigSchema];
73
+ get accept() {
74
+ return this.config.accept;
75
+ }
76
+ get ipfsGateway() {
77
+ return this.params.ipfsGateway;
78
+ }
79
+ async observeHandler(inPayloads = []) {
80
+ await this.started("throw");
81
+ try {
82
+ const observations = await Promise.all(
83
+ inPayloads.filter((0, import_payload_model.isPayloadOfSchemaType)(ApiCallSchema)).map(async (call) => {
84
+ const { uri, verb } = call;
85
+ const validatedUri = (0, import_assert2.assertEx)(checkIpfsUrl(uri, this.ipfsGateway), "Invalid URI");
86
+ if (verb === "get") {
87
+ return this.httpGet(validatedUri, uri);
88
+ }
89
+ const observation = {
90
+ call: await import_hash.PayloadHasher.hashAsync(call),
91
+ schema: ApiCallResultSchema
92
+ };
93
+ return observation;
94
+ })
95
+ );
96
+ return observations;
97
+ } catch (ex) {
98
+ const error = ex;
99
+ console.log(`Error [${this.config.name}]: ${error.message}`);
100
+ throw error;
101
+ }
102
+ }
103
+ async httpGet(url, call) {
104
+ var _a, _b, _c;
105
+ const result = {
106
+ call,
107
+ schema: ApiCallResultSchema
108
+ };
109
+ try {
110
+ switch (this.accept) {
111
+ case "application/json": {
112
+ const axios = new import_axios.AxiosJson();
113
+ const response = await axios.get(url);
114
+ if (response.status >= 200 && response.status < 300) {
115
+ const jsonResult = result;
116
+ jsonResult.data = response.data;
117
+ jsonResult.contentType = "application/json";
118
+ } else {
119
+ const errorResult = result;
120
+ errorResult.http = {
121
+ status: response.status
122
+ };
123
+ }
124
+ break;
125
+ }
126
+ default: {
127
+ const axios = new import_axios.Axios({ responseType: "arraybuffer" });
128
+ const response = await axios.get(url);
129
+ if (response.status >= 200 && response.status < 300) {
130
+ const jsonResult = result;
131
+ jsonResult.data = (0, import_base64_js.fromByteArray)(import_buffer.Buffer.from(response.data, "binary"));
132
+ jsonResult.contentType = ((_a = response.headers["content-type"]) == null ? void 0 : _a.toString()) ?? "application/octet-stream";
133
+ } else {
134
+ const errorResult = result;
135
+ errorResult.http = {
136
+ status: response.status
137
+ };
138
+ }
139
+ break;
140
+ }
141
+ }
142
+ } catch (ex) {
143
+ const axiosError = ex;
144
+ if (axiosError.isAxiosError) {
145
+ if (((_b = axiosError == null ? void 0 : axiosError.response) == null ? void 0 : _b.status) !== void 0) {
146
+ result.http = result.http ?? {};
147
+ result.http.status = (_c = axiosError == null ? void 0 : axiosError.response) == null ? void 0 : _c.status;
148
+ }
149
+ if ((axiosError == null ? void 0 : axiosError.code) !== void 0) {
150
+ result.http = result.http ?? {};
151
+ result.http.code = axiosError == null ? void 0 : axiosError.code;
152
+ }
153
+ return result;
154
+ } else {
155
+ throw ex;
156
+ }
157
+ }
158
+ return result;
159
+ }
160
+ };
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {
163
+ ApiCallResultSchema,
164
+ ApiCallSchema,
165
+ ApiCallWitness,
166
+ ApiCallWitnessConfigSchema
167
+ });
168
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Payload.ts","../../src/Witness.ts","../../src/lib/checkIpfsUrl.ts"],"sourcesContent":["export * from './Payload'\nexport * from './Witness'\n","import { Hash } from '@xyo-network/hash'\nimport { 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'\n\nexport type ApiCall = Payload<\n {\n uri: string\n verb?: Verb\n },\n ApiCallSchema\n>\n\nexport const ApiCallResultSchema = 'network.xyo.api.call.result'\nexport type ApiCallResultSchema = typeof ApiCallResultSchema\n\nexport interface HttpMeta {\n code?: string\n status?: number\n}\n\nexport type ApiCallJsonResult<T extends object | [] = object> = Payload<\n {\n call: Hash\n contentType: 'application/json'\n data: T\n },\n ApiCallResultSchema\n>\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 = ApiCallBase64Result | ApiCallJsonResult | ApiCallErrorResult\n","import { assertEx } from '@xylabs/assert'\nimport { Axios, AxiosError, AxiosJson } from '@xylabs/axios'\nimport { Buffer } from '@xylabs/buffer'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { Hash, PayloadHasher } from '@xyo-network/hash'\nimport { JsonArray, JsonObject } from '@xyo-network/object'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { fromByteArray } from 'base64-js'\n\nimport { checkIpfsUrl } from './lib'\nimport {\n ApiCall,\n ApiCallBase64Result,\n ApiCallErrorResult,\n ApiCallJsonResult,\n ApiCallResult,\n ApiCallResultSchema,\n ApiCallSchema,\n Verb,\n} from './Payload'\n\nexport const ApiCallWitnessConfigSchema = 'network.xyo.api.call.witness.config'\nexport type ApiCallWitnessConfigSchema = typeof ApiCallWitnessConfigSchema\n\nexport type ApiCallWitnessConfig = WitnessConfig<{\n accept: 'application/json'\n schema: ApiCallWitnessConfigSchema\n verb?: Verb\n}>\n\nexport type ApiCallWitnessParams = WitnessParams<ApiCallWitnessConfig, { ipfsGateway?: string }>\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\n }\n\n get ipfsGateway() {\n return this.params.ipfsGateway\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 { uri, verb } = 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.hashAsync(call),\n schema: ApiCallResultSchema,\n }\n return observation\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.log(`Error [${this.config.name}]: ${error.message}`)\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()\n const response = await axios.get<JsonArray | JsonObject>(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({ responseType: 'arraybuffer' })\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\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) => {\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 {\n return urlToCheck\n }\n } catch (ex) {\n const error = ex as Error\n console.error(`${error.name}:${error.message} [${urlToCheck}]`)\n console.log(error.stack)\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,gBAAgB;AAatB,IAAM,sBAAsB;;;AChBnC,IAAAA,iBAAyB;AACzB,mBAA6C;AAC7C,oBAAuB;AACvB,8BAAgC;AAChC,kBAAoC;AAEpC,2BAAsC;AAEtC,uBAA8B;;;ACR9B,oBAAyB;AAQlB,IAAM,eAAe,CAAC,YAAoB,gBAAyB;AACxE,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,UAAU;AAC9B,QAAI,WAAW,IAAI;AACnB,QAAI,OAAO,IAAI;AACf,QAAI,OAAO,IAAI;AACf,UAAM,QAAQ,IAAI;AAClB,QAAI,aAAa,SAAS;AACxB,iBAAW;AACX,iBAAO,wBAAS,aAAa,yBAAyB;AACtD,aAAO,I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,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_assert"]}
@@ -0,0 +1,3 @@
1
+ export * from './Payload';
2
+ export * from './Witness';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './Payload';
2
+ export * from './Witness';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './Payload';
2
+ export * from './Witness';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}