Skip to content

Commit a5b636f

Browse files
authored
feat(docs): add node snippets locally (#689)
* feat(docs): update ChunkedSnippet component to take in a path * feat: add node snippets * feat(docs): update node snippets to reference local snippet file * feat(docs): add JS snippets * chore(docs): replace LinkOut snippets reference to local file
1 parent 440a5ba commit a5b636f

File tree

68 files changed

+2163
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2163
-120
lines changed

docs/src/components/ChunkedSnippet.astro

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
---
2+
import fs from "node:fs/promises"
3+
import path from "node:path"
4+
import { execSync } from 'node:child_process';
25
import prettier from 'prettier';
36
import { Code } from 'astro:components';
47
import { CodeBlock } from '@interledger/docs-design-system'
5-
const {source, chunk} = Astro.props;
8+
const {source, chunk, l} = Astro.props;
69
import * as phpPlugin from '@prettier/plugin-php'
710
8-
// Retrieve code snippet from GitHub as text
9-
const getApiData = async () => {
10-
const data = await fetch(source).then((response) => response.text());
11-
return data;
12-
};
13-
const code = await getApiData();
11+
const gitRoot = execSync('git rev-parse --show-toplevel').toString().trim();
12+
const snippetsPath = path.join(gitRoot, 'snippets');
13+
14+
const getChunk = async () => {
15+
if (source.startsWith('http')) {
16+
const data = await fetch(source).then((response) => response.text());
17+
return data;
18+
}
19+
20+
const data = await fs.readFile(path.join(snippetsPath, l, source), {encoding: "utf8"})
21+
return data
22+
}
23+
24+
const code = await getChunk()
1425
1526
// Split the text into an array of lines
1627
const lines = code.split('\n');
@@ -221,4 +232,4 @@ const codeBlockTitle = codeChunkArray[chunkNumber]?.title;
221232
})
222233
});
223234
});
224-
</script>
235+
</script>

docs/src/content/docs/es/guides/make-onetime-payment.mdx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ En esta guía, encontrará los pasos que debe seguir para efectuar un pago únic
4141
### 1. Obtener los datos de la dirección de billetera del destinatario
4242

4343
<ChunkedSnippet
44-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
44+
source='grant/grant-outgoing-payment.ts'
45+
l='node'
4546
chunk='3'
4647
/>
4748

@@ -50,7 +51,8 @@ En esta guía, encontrará los pasos que debe seguir para efectuar un pago únic
5051
Solicitar una concesión de autorización para un `incomingPayment` desde el servidor de autorización de la billetera del destinatario.
5152

5253
<ChunkedSnippet
53-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-incoming-payment.ts'
54+
source='grant/grant-incoming-payment.ts'
55+
l='node'
5456
chunk='4'
5557
/>
5658

@@ -67,7 +69,8 @@ Agregar el objeto `incomingAmount` y definir las siguientes propiedades:
6769
De modo opcional, puede agregar la propiedad `expiresAt`, que es la fecha y la hora a partir de la que ya no se aceptarán pagos entrantes.
6870

6971
<ChunkedSnippet
70-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/incoming-payment/incoming-payment-create.ts'
72+
source='incoming-payment/incoming-payment-create.ts'
73+
l='node'
7174
chunk='3'
7275
/>
7376

@@ -76,7 +79,8 @@ De modo opcional, puede agregar la propiedad `expiresAt`, que es la fecha y la h
7679
Solicitar una concesión de autorización para una `quote` desde el servidor de autorización de la billetera del remitente.
7780

7881
<ChunkedSnippet
79-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-quote.ts'
82+
source='grant/grant-quote.ts'
83+
l='node'
8084
chunk='4'
8185
/>
8286

@@ -91,7 +95,8 @@ Agregar las siguientes propiedades:
9195
- `receiver`: la URL del pago entrante que recibirá el pago.
9296

9397
<ChunkedSnippet
94-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/quote/quote-create.ts'
98+
source='/quote/quote-create.ts'
99+
l='node'
95100
chunk='3'
96101
/>
97102

@@ -122,12 +127,14 @@ Ahora indique que su cliente puede recibir una señal del servidor de autorizaci
122127
4. Crear un `nonce` para que su cliente lo utilice a la hora de verificar que el servidor de autorización sea la misma entidad a lo largo de todo el proceso. Este código puede ser cualquier cadena aleatoria y difícil de descifrar.
123128

124129
<ChunkedSnippet
125-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
130+
source='grant/grant-outgoing-payment.ts'
131+
l='node'
126132
chunk='4'
127133
/>
128134

129135
<ChunkedSnippet
130-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
136+
source='grant/grant-outgoing-payment.ts'
137+
l='node'
131138
chunk='5'
132139
/>
133140

@@ -146,7 +153,8 @@ Una vez que el usuario completó su interacción con el proveedor de identidad (
146153
Agregue la referencia a la interacción del servidor de autorización como el valor `interact_ref` al cuerpo de su solicitud de continuación.
147154

148155
<ChunkedSnippet
149-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-continuation.ts'
156+
source='grant/grant-continuation.ts'
157+
l='node'
150158
chunk='3'
151159
/>
152160

@@ -199,7 +207,8 @@ Agregar las siguientes propiedades:
199207
- `quoteId`: la URL de la cotización en la que se especifica el monto del pago.
200208

201209
<ChunkedSnippet
202-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/outgoing-payment/outgoing-payment-create.ts'
210+
source='outgoing-payment/outgoing-payment-create.ts'
211+
l='node'
203212
chunk='3'
204213
/>
205214

docs/src/content/docs/es/guides/make-recurring-payments.mdx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ En esta guía, encontrará pasos para realizar pagos recurrentes, en los que una
4242
### 1. Obtener los datos de la dirección de billetera del destinatario
4343

4444
<ChunkedSnippet
45-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
45+
source='grant/grant-outgoing-payment.ts'
46+
l='node'
4647
chunk='3'
4748
/>
4849

@@ -51,7 +52,8 @@ En esta guía, encontrará pasos para realizar pagos recurrentes, en los que una
5152
Solicitar una concesión de autorización para un `incomingPayment` desde el servidor de autorización de la billetera del destinatario.
5253

5354
<ChunkedSnippet
54-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-incoming-payment.ts'
55+
source='grant/grant-incoming-payment.ts'
56+
l='node'
5557
chunk='4'
5658
/>
5759

@@ -68,7 +70,8 @@ Agregar el objeto `incomingAmount` y definir las siguientes propiedades:
6870
De modo opcional, puede agregar la propiedad `expiresAt`, que es la fecha y la hora a partir de la que ya no se aceptarán pagos entrantes.
6971

7072
<ChunkedSnippet
71-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/incoming-payment/incoming-payment-create.ts'
73+
source='incoming-payment/incoming-payment-create.ts'
74+
l='node'
7275
chunk='3'
7376
/>
7477

@@ -77,7 +80,8 @@ De modo opcional, puede agregar la propiedad `expiresAt`, que es la fecha y la h
7780
Solicitar una concesión de autorización para una `quote` desde el servidor de autorización de la billetera del remitente.
7881

7982
<ChunkedSnippet
80-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-quote.ts'
83+
source='grant/grant-quote.ts'
84+
l='node'
8185
chunk='4'
8286
/>
8387

@@ -92,7 +96,8 @@ Agregar las siguientes propiedades:
9296
- `receiver`: la URL del pago entrante que recibirá el pago.
9397

9498
<ChunkedSnippet
95-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/quote/quote-create.ts'
99+
source='quote/quote-create.ts'
100+
l='node'
96101
chunk='3'
97102
/>
98103

@@ -127,12 +132,14 @@ Ahora indique que su cliente puede recibir una señal del servidor de autorizaci
127132
4. Crear un `nonce` para que su cliente lo utilice a la hora de verificar que el servidor de autorización sea la misma entidad a lo largo de todo el proceso. Este código puede ser cualquier cadena aleatoria y difícil de descifrar.
128133

129134
<ChunkedSnippet
130-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
135+
source='grant/grant-outgoing-payment.ts'
136+
l='node'
131137
chunk='4'
132138
/>
133139

134140
<ChunkedSnippet
135-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
141+
source='grant/grant-outgoing-payment.ts'
142+
l='node'
136143
chunk='5'
137144
/>
138145

@@ -151,7 +158,8 @@ Una vez que el usuario completó su interacción con el proveedor de identidad (
151158
Agregue la referencia a la interacción del servidor de autorización como el valor `interact_ref` al cuerpo de su solicitud de continuación.
152159

153160
<ChunkedSnippet
154-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-continuation.ts'
161+
source='grant/grant-continuation.ts'
162+
l='node'
155163
chunk='3'
156164
/>
157165

@@ -204,7 +212,8 @@ Agregar las siguientes propiedades:
204212
- `quoteId`: la URL de la cotización en la que se especifica el monto del pago.
205213

206214
<ChunkedSnippet
207-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/outgoing-payment/outgoing-payment-create.ts'
215+
source='outgoing-payment/outgoing-payment-create.ts'
216+
l='node'
208217
chunk='3'
209218
/>
210219

@@ -217,7 +226,8 @@ Este paso solo se requiere si el token de acceso que obtuvo en la solicitud de c
217226
Rote el token de acceso obtenido en la solicitud de concesión `outgoingPayment` anterior.
218227

219228
<ChunkedSnippet
220-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/token/token-rotate.ts'
229+
source='token/token-rotate.ts'
230+
l='node'
221231
chunk='3'
222232
/>
223233

@@ -231,7 +241,8 @@ Agregar las siguientes propiedades:
231241
- `quoteId`: la URL de la cotización en la que se especifica el monto del pago.
232242

233243
<ChunkedSnippet
234-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/outgoing-payment/outgoing-payment-create.ts'
244+
source='outgoing-payment/outgoing-payment-create.ts'
245+
l='node'
235246
chunk='3'
236247
/>
237248

docs/src/content/docs/sdk/grant-continue.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,26 @@ After the user completes their interaction with the identity provider (IdP), the
3838
<TsImport />
3939

4040
<ChunkedSnippet
41-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-continuation.ts'
41+
source='grant/grant-continuation.ts'
42+
l='node'
4243
chunk='3'
4344
/>
4445

4546
<ChunkedSnippet
46-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-continuation.ts'
47+
source='grant/grant-continuation.ts'
48+
l='node'
4749
chunk='4'
4850
/>
4951

5052
<ChunkedSnippet
51-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-continuation.ts'
53+
source='grant/grant-continuation.ts'
54+
l='node'
5255
chunk='5'
5356
/>
5457

55-
For TypeScript, run `tsx path/to/directory/index.ts`. <LinkOut href='https://github.com/interledger/open-payments-snippets/blob/main/grant/grant-continuation.ts'>View full TS source</LinkOut>
58+
For TypeScript, run `tsx path/to/directory/index.ts`. <LinkOut href='https://github.com/interledger/open-payments/blob/main/snippets/node/grant/grant-continuation.ts'>View full TS source</LinkOut>
5659

57-
For JavaScript, run `node path/to/directory/index.js`. <LinkOut href='https://github.com/interledger/open-payments-snippets/blob/main/grant/grant-continuation.js'>View full JS source</LinkOut>
60+
For JavaScript, run `node path/to/directory/index.js`. <LinkOut href='https://github.com/interledger/open-payments/blob/main/snippets/node/grant/grant-continuation.js'>View full JS source</LinkOut>
5861

5962
</TabItem>
6063
<TabItem label="PHP" icon='seti:php'>

docs/src/content/docs/sdk/grant-create-incoming.mdx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,40 @@ The snippets below enable a client to request a grant for an incoming payment. T
3434
<TsImport />
3535

3636
<ChunkedSnippet
37-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-incoming-payment.ts'
37+
source='grant/grant-incoming-payment.ts'
38+
l='node'
3839
chunk='3'
3940
/>
4041

4142
<ChunkedSnippet
42-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-incoming-payment.ts'
43+
source='grant/grant-incoming-payment.ts'
44+
l='node'
4345
chunk='4'
4446
/>
4547

4648
<ChunkedSnippet
47-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-incoming-payment.ts'
49+
source='grant/grant-incoming-payment.ts'
50+
l='node'
4851
chunk='5'
4952
/>
5053

5154
<ChunkedSnippet
52-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-incoming-payment.ts'
55+
source='grant/grant-incoming-payment.ts'
56+
l='node'
5357
chunk='6'
5458
/>
5559

56-
For TypeScript, run `tsx path/to/directory/index.ts`. <LinkOut href='https://github.com/interledger/open-payments-snippets/blob/main/grant/grant-incoming-payment.ts'>View full TS source</LinkOut>
60+
For TypeScript, run `tsx path/to/directory/index.ts`. <LinkOut href='https://github.com/interledger/open-payments/blob/main/snippets/node/grant/grant-incoming-payment.ts'>View full TS source</LinkOut>
5761

58-
For JavaScript, run `node path/to/directory/index.js`. <LinkOut href='https://github.com/interledger/open-payments-snippets/blob/main/grant/grant-incoming-payment.js'>View full JS source</LinkOut>
62+
For JavaScript, run `node path/to/directory/index.js`. <LinkOut href='https://github.com/interledger/open-payments/blob/main/snippets/node/grant/grant-incoming-payment.js'>View full JS source</LinkOut>
5963

6064
</TabItem>
6165
<TabItem label="PHP" icon='seti:php'>
6266
<LinkButton href="https://github.com/interledger/open-payments-php-snippets/blob/main/README.md#prerequisites" target="_blank" icon="external" iconPlacement="start">Prerequisites</LinkButton>
6367

6468
<PhpImport />
6569

66-
<ChunkedSnippet
70+
{/* <ChunkedSnippet
6771
source='https://raw.githubusercontent.com/interledger/open-payments-php-snippets/refs/heads/main/src/Command/Grant/GrantIncomingPayment.php'
6872
chunk='3'
6973
/>
@@ -78,7 +82,7 @@ For JavaScript, run `node path/to/directory/index.js`. <LinkOut href='https://gi
7882
<ChunkedSnippet
7983
source='https://raw.githubusercontent.com/interledger/open-payments-php-snippets/refs/heads/main/src/Command/Grant/GrantIncomingPayment.php'
8084
chunk='6'
81-
/>
85+
/> */}
8286
{/* prettier-ignore */}
8387

8488
<p><LinkOut href='https://github.com/interledger/open-payments-php-snippets/blob/main/src/Command/Grant/GrantIncomingPayment.php'>View full source</LinkOut></p>

docs/src/content/docs/sdk/grant-create-outgoing.mdx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,42 @@ Open Payments also requires any authorization server that issues interactive gra
3838
<TsImport />
3939

4040
<ChunkedSnippet
41-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
41+
source='grant/grant-outgoing-payment.ts'
42+
l='node'
4243
chunk='3'
4344
/>
4445

4546
#### Generate without an interval
4647

4748
<ChunkedSnippet
48-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
49+
source='grant/grant-outgoing-payment.ts'
50+
l='node'
4951
chunk='4'
5052
/>
5153

5254
#### Generate with an interval
5355

5456
<ChunkedSnippet
55-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/refs/heads/main/grant/grant-outgoing-payment-interval.ts'
57+
source='grant/grant-outgoing-payment-interval.ts'
58+
l='node'
5659
chunk='4'
5760
/>
5861

5962
<ChunkedSnippet
60-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
63+
source='grant/grant-outgoing-payment.ts'
64+
l='node'
6165
chunk='5'
6266
/>
6367

6468
<ChunkedSnippet
65-
source='https://raw.githubusercontent.com/interledger/open-payments-snippets/main/grant/grant-outgoing-payment.ts'
69+
source='grant/grant-outgoing-payment.ts'
70+
l='node'
6671
chunk='6'
6772
/>
6873

69-
For TypeScript, run `tsx path/to/directory/index.ts`. <LinkOut href='https://github.com/interledger/open-payments-snippets/blob/main/grant/grant-outgoing-payment.ts'>View full TS source</LinkOut>
74+
For TypeScript, run `tsx path/to/directory/index.ts`. <LinkOut href='https://github.com/interledger/open-payments/blob/main/snippets/node/grant/grant-outgoing-payment.ts'>View full TS source</LinkOut>
7075

71-
For JavaScript, run `node path/to/directory/index.js`. <LinkOut href='https://github.com/interledger/open-payments-snippets/blob/main/grant/grant-outgoing-payment.js'>View full JS source</LinkOut>
76+
For JavaScript, run `node path/to/directory/index.js`. <LinkOut href='https://github.com/interledger/open-payments/blob/main/snippets/node/grant/grant-outgoing-payment.js'>View full JS source</LinkOut>
7277

7378
</TabItem>
7479
<TabItem label="PHP" icon='seti:php'>

0 commit comments

Comments
 (0)