@shellicar/svelte-adapter-azure-functions 0.1.1 → 0.2.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/LICENSE +21 -0
- package/README.md +10 -54
- package/dist/{chunk-PJIDA4TG.js → chunk-POAQL7D4.js} +1 -1
- package/dist/chunk-XDKFIHKQ.js +1 -0
- package/dist/chunk-XDKFIHKQ.js.map +1 -0
- package/dist/handler.js +1 -1
- package/dist/headers.js +1 -1
- package/dist/shims.js.map +1 -1
- package/dist/trigger.js +1 -1
- package/dist/trigger.js.map +1 -1
- package/package.json +25 -26
- package/dist/chunk-PSBHP5ZD.js +0 -1
- package/dist/chunk-PSBHP5ZD.js.map +0 -1
- /package/dist/{chunk-PJIDA4TG.js.map → chunk-POAQL7D4.js.map} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Stephen Hellicar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,35 +1,20 @@
|
|
|
1
1
|
# @shellicar/svelte-adapter-azure-functions
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[][sveltekit]
|
|
5
|
-
[][typescript]
|
|
6
|
-
[][biome]
|
|
3
|
+
> A [SvelteKit adapter](https://kit.svelte.dev/docs/adapters) that builds your app into an Azure Function.
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
[](https://npmjs.com/package/@shellicar/svelte-adapter-azure-functions)
|
|
6
|
+
[](https://github.com/shellicar/svelte-adapter-azure-functions/actions/workflows/node.js.yml)
|
|
9
7
|
|
|
10
|
-
##
|
|
8
|
+
## Installation & Quick Start
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## Implementation
|
|
15
|
-
|
|
16
|
-
The adapter generates a single Azure Function:
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
app.http('server', {
|
|
20
|
-
handler,
|
|
21
|
-
route: '{*url}',
|
|
22
|
-
methods: ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT']
|
|
23
|
-
});
|
|
10
|
+
```sh
|
|
11
|
+
npm i --save @shellicar/svelte-adapter-azure-functions
|
|
24
12
|
```
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
pnpm add -D @shellicar/svelte-adapter-azure-functions
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add @shellicar/svelte-adapter-azure-functions
|
|
30
16
|
```
|
|
31
17
|
|
|
32
|
-
In `svelte.config.js`:
|
|
33
18
|
```js
|
|
34
19
|
import adapter from '@shellicar/svelte-adapter-azure-functions';
|
|
35
20
|
|
|
@@ -40,35 +25,6 @@ export default {
|
|
|
40
25
|
};
|
|
41
26
|
```
|
|
42
27
|
|
|
43
|
-
##
|
|
44
|
-
|
|
45
|
-
### esbuildOptions
|
|
46
|
-
|
|
47
|
-
```js
|
|
48
|
-
adapter({
|
|
49
|
-
esbuildOptions: {
|
|
50
|
-
minify: false
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Default options in [defaults.ts](./src/defaults.ts):
|
|
56
|
-
```typescript
|
|
57
|
-
export const defaults = {
|
|
58
|
-
bundle: true,
|
|
59
|
-
platform: 'node',
|
|
60
|
-
target: 'node20',
|
|
61
|
-
format: 'esm',
|
|
62
|
-
// ...see defaults.ts for full options
|
|
63
|
-
};
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Credits
|
|
67
|
-
|
|
68
|
-
* [svelte-adapter-azure-swa](https://github.com/geoffrich/svelte-adapter-azure-swa)
|
|
69
|
-
* [esbuild-azure-functions](https://github.com/beyerleinf/esbuild-azure-functions)
|
|
28
|
+
## Documentation
|
|
70
29
|
|
|
71
|
-
[
|
|
72
|
-
[sveltekit]: https://kit.svelte.dev
|
|
73
|
-
[typescript]: https://www.typescriptlang.org
|
|
74
|
-
[biome]: https://biomejs.dev
|
|
30
|
+
For full documentation, visit [here](https://github.com/shellicar/svelte-adapter-azure-functions).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getClientIPFromHeaders as e,getClientPrincipalFromHeaders as r,splitCookiesFromHeaders as t}from"./chunk-
|
|
1
|
+
import{getClientIPFromHeaders as e,getClientPrincipalFromHeaders as r,splitCookiesFromHeaders as t}from"./chunk-XDKFIHKQ.js";import{serverPromise as s}from"./chunk-GKOGVGYC.js";import{__name as a,init_cjs_shim as o}from"./chunk-AW5NC2LL.js";o();var n=a((async e=>{const{method:r,headers:t,url:s}=e,a={method:r,headers:Object.fromEntries(t)};return"GET"!==r&&"HEAD"!==r&&(a.body=await e.arrayBuffer()),new Request(s,a)}),"toRequest"),d=a((async(a,o)=>{const d=await n(a),i=await s,c=e(d.headers),h=r(d.headers),u=await i.respond(d,{getClientAddress:()=>c,platform:{clientPrincipal:h,context:o}}),{headers:m,cookies:f}=t(u.headers);return{status:u.status,body:u.body,headers:m,cookies:f}}),"handler");export{d as handler};//# sourceMappingURL=chunk-POAQL7D4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as e,init_cjs_shim as r}from"./chunk-AW5NC2LL.js";r();import{parse as o,splitCookiesString as t}from"set-cookie-parser";var i=e((e=>{const r={},i=[];return e.forEach(((e,s)=>{if("set-cookie"===s){const r=t(e);i.push(...o(r))}else r[s]=e})),{headers:r,cookies:i}}),"splitCookiesFromHeaders"),s=e((e=>{const r=e.get("x-forwarded-for")??"127.0.0.1",[o]=r.split(", "),[t]=o.split(":");return t}),"getClientIPFromHeaders");function n(e){const r=e.get("x-ms-client-principal");if(r)try{const e=Buffer.from(r,"base64").toString("ascii");return JSON.parse(e)}catch(e){return void console.log("Unable to parse client principal:",e)}}e(n,"getClientPrincipalFromHeaders");export{i as splitCookiesFromHeaders,s as getClientIPFromHeaders,n as getClientPrincipalFromHeaders};//# sourceMappingURL=chunk-XDKFIHKQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/headers.ts"],"sourcesContent":["import type { Cookie } from '@azure/functions';\nimport { parse, splitCookiesString } from 'set-cookie-parser';\nimport type { ClientPrincipal } from './types';\n\n/**\n * Splits 'set-cookie' headers into individual cookies\n */\nexport const splitCookiesFromHeaders = (headers: Headers): { headers: Record<string, string>; cookies: Cookie[] } => {\n const resHeaders: Record<string, string> = {};\n const resCookies: Cookie[] = [];\n\n headers.forEach((value, key) => {\n if (key === 'set-cookie') {\n const cookieStrings = splitCookiesString(value);\n resCookies.push(...(parse(cookieStrings) as Cookie[]));\n } else {\n resHeaders[key] = value;\n }\n });\n\n return { headers: resHeaders, cookies: resCookies };\n};\n\nexport const getClientIPFromHeaders = (headers: Headers): string => {\n const resHeader = headers.get('x-forwarded-for') ?? '127.0.0.1';\n const [origin] = resHeader.split(', ');\n const [ipAddress] = origin.split(':');\n return ipAddress;\n};\n\n/**\n * Gets the client principal from `x-ms-client-principal` header.\n */\nexport function getClientPrincipalFromHeaders(headers: Headers): ClientPrincipal | undefined {\n // Code adapted from the official SWA documentation\n // https://learn.microsoft.com/en-us/azure/static-web-apps/user-information?tabs=javascript#api-functions\n const header = headers.get('x-ms-client-principal');\n if (!header) {\n return undefined;\n }\n\n try {\n const encoded = Buffer.from(header, 'base64');\n const decoded = encoded.toString('ascii');\n const clientPrincipal = JSON.parse(decoded);\n\n return clientPrincipal;\n } catch (e) {\n console.log('Unable to parse client principal:', e);\n return undefined;\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,SAAS,OAAO,0BAA0B;AAMnC,IAAM,0BAA0B,wBAAC,YAA6E;AACnH,QAAM,aAAqC,CAAC;AAC5C,QAAM,aAAuB,CAAC;AAE9B,UAAQ,QAAQ,CAAC,OAAO,QAAQ;AAC9B,QAAI,QAAQ,cAAc;AACxB,YAAM,gBAAgB,mBAAmB,KAAK;AAC9C,iBAAW,KAAK,GAAI,MAAM,aAAa,CAAc;AAAA,IACvD,OAAO;AACL,iBAAW,GAAG,IAAI;AAAA,IACpB;AAAA,EACF,CAAC;AAED,SAAO,EAAE,SAAS,YAAY,SAAS,WAAW;AACpD,GAduC;AAgBhC,IAAM,yBAAyB,wBAAC,YAA6B;AAClE,QAAM,YAAY,QAAQ,IAAI,iBAAiB,KAAK;AACpD,QAAM,CAAC,MAAM,IAAI,UAAU,MAAM,IAAI;AACrC,QAAM,CAAC,SAAS,IAAI,OAAO,MAAM,GAAG;AACpC,SAAO;AACT,GALsC;AAU/B,SAAS,8BAA8B,SAA+C;AAG3F,QAAM,SAAS,QAAQ,IAAI,uBAAuB;AAClD,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,UAAU,OAAO,KAAK,QAAQ,QAAQ;AAC5C,UAAM,UAAU,QAAQ,SAAS,OAAO;AACxC,UAAM,kBAAkB,KAAK,MAAM,OAAO;AAE1C,WAAO;AAAA,EACT,SAAS,GAAG;AACV,YAAQ,IAAI,qCAAqC,CAAC;AAClD,WAAO;AAAA,EACT;AACF;AAlBgB;","names":[]}
|
package/dist/handler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handler as o}from"./chunk-
|
|
1
|
+
import{handler as o}from"./chunk-POAQL7D4.js";import"./chunk-XDKFIHKQ.js";import"./chunk-GKOGVGYC.js";import"./chunk-AW5NC2LL.js";export{o as handler};//# sourceMappingURL=handler.js.map
|
package/dist/headers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getClientIPFromHeaders as o,getClientPrincipalFromHeaders as r,splitCookiesFromHeaders as m}from"./chunk-
|
|
1
|
+
import{getClientIPFromHeaders as o,getClientPrincipalFromHeaders as r,splitCookiesFromHeaders as m}from"./chunk-XDKFIHKQ.js";import"./chunk-AW5NC2LL.js";export{o as getClientIPFromHeaders,r as getClientPrincipalFromHeaders,m as splitCookiesFromHeaders};//# sourceMappingURL=headers.js.map
|
package/dist/shims.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shims.ts","
|
|
1
|
+
{"version":3,"sources":["../src/shims.ts","../../../node_modules/.pnpm/@sveltejs+kit@2.15.2_@sveltejs+vite-plugin-svelte@5.0.3_svelte@5.17.1_vite@6.0.7_@types+node@_qlt44birs4qclslvkzfhazsygi/node_modules/@sveltejs/kit/src/exports/node/polyfills.js"],"sourcesContent":["import { installPolyfills } from '@sveltejs/kit/node/polyfills';\ninstallPolyfills();\n","import buffer from 'node:buffer';\nimport { webcrypto as crypto } from 'node:crypto';\n\n// `buffer.File` was added in Node 18.13.0 while the `File` global was added in Node 20.0.0\nconst File = /** @type {import('node:buffer') & { File?: File}} */ (buffer).File;\n\n/** @type {Record<string, any>} */\nconst globals = {\n\tcrypto,\n\tFile\n};\n\n// exported for dev/preview and node environments\n/**\n * Make various web APIs available as globals:\n * - `crypto`\n * - `File`\n */\nexport function installPolyfills() {\n\tfor (const name in globals) {\n\t\tif (name in globalThis) continue;\n\n\t\tObject.defineProperty(globalThis, name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t\twritable: true,\n\t\t\tvalue: globals[name]\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;AAAA;;;ACAA;AAAA,OAAO,YAAY;AACnB,SAAS,aAAa,cAAc;AAGpC,IAAM;AAAA;AAAA,EAA8D,OAAQ;AAAA;AAG5E,IAAM,UAAU;AAAA,EACf;AAAA,EACA;AACD;AAQO,SAAS,mBAAmB;AAClC,aAAW,QAAQ,SAAS;AAC3B,QAAI,QAAQ,WAAY;AAExB,WAAO,eAAe,YAAY,MAAM;AAAA,MACvC,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,UAAU;AAAA,MACV,OAAO,QAAQ,IAAI;AAAA,IACpB,CAAC;AAAA,EACF;AACD;AAXgB;;;ADjBhB,iBAAiB;","names":[]}
|