@walkeros/server-source-gcp 0.4.2 → 0.5.1-next.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/README.md +49 -8
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,6 +9,25 @@ runtime adapters for GCP services.
|
|
|
9
9
|
npm install @walkeros/server-source-gcp @google-cloud/functions-framework
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import {
|
|
16
|
+
sourceCloudFunction,
|
|
17
|
+
type SourceCloudFunction,
|
|
18
|
+
} from '@walkeros/server-source-gcp';
|
|
19
|
+
import { startFlow } from '@walkeros/collector';
|
|
20
|
+
import { http } from '@google-cloud/functions-framework';
|
|
21
|
+
|
|
22
|
+
const { elb } = await startFlow<SourceCloudFunction.Push>({
|
|
23
|
+
sources: { api: { code: sourceCloudFunction } },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
http('walkerHandler', elb);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
12
31
|
## Cloud Functions Source
|
|
13
32
|
|
|
14
33
|
The Cloud Functions source provides an HTTP handler that receives walker events
|
|
@@ -17,17 +36,39 @@ and forwards them to the walkerOS collector.
|
|
|
17
36
|
### Basic Usage
|
|
18
37
|
|
|
19
38
|
```typescript
|
|
20
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
sourceCloudFunction,
|
|
41
|
+
type SourceCloudFunction,
|
|
42
|
+
} from '@walkeros/server-source-gcp';
|
|
43
|
+
import { startFlow } from '@walkeros/collector';
|
|
21
44
|
import { http } from '@google-cloud/functions-framework';
|
|
22
45
|
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
46
|
+
// Handler singleton - reused across warm invocations
|
|
47
|
+
let handler: SourceCloudFunction.Push;
|
|
48
|
+
|
|
49
|
+
async function setup() {
|
|
50
|
+
if (handler) return handler;
|
|
51
|
+
|
|
52
|
+
const { elb } = await startFlow<SourceCloudFunction.Push>({
|
|
53
|
+
sources: {
|
|
54
|
+
api: {
|
|
55
|
+
code: sourceCloudFunction,
|
|
56
|
+
config: {
|
|
57
|
+
settings: { cors: true },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
destinations: {
|
|
62
|
+
// Your destinations
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
handler = elb;
|
|
67
|
+
return handler;
|
|
68
|
+
}
|
|
28
69
|
|
|
29
|
-
//
|
|
30
|
-
http('walkerHandler',
|
|
70
|
+
// Register with Cloud Functions framework
|
|
71
|
+
setup().then((h) => http('walkerHandler', h));
|
|
31
72
|
```
|
|
32
73
|
|
|
33
74
|
## Bundler Integration
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var mod,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},index_exports={};__export(index_exports,{SourceCloudFunction:()=>types_exports,examples:()=>examples_exports,schemas:()=>schemas_exports,sourceCloudFunction:()=>cloudfunction_default}),module.exports=(mod=index_exports,((to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to})(__defProp({},"__esModule",{value:!0}),mod));var types_exports={},schemas_exports={};__export(schemas_exports,{CorsOptionsSchema:()=>CorsOptionsSchema,CorsOrigin:()=>CorsOrigin,HttpMethod:()=>HttpMethod,SettingsSchema:()=>SettingsSchema,settings:()=>settings});var import_dev3=require("@walkeros/core/dev"),import_dev2=require("@walkeros/core/dev"),import_dev=require("@walkeros/core/dev"),HttpMethod=import_dev.z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),CorsOrigin=import_dev.z.union([import_dev.z.string(),import_dev.z.array(import_dev.z.string()),import_dev.z.literal("*")]),CorsOptionsSchema=import_dev.z.object({origin:CorsOrigin.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:import_dev.z.array(HttpMethod).describe("Allowed HTTP methods").optional(),headers:import_dev.z.array(import_dev.z.string()).describe("Allowed request headers").optional(),credentials:import_dev.z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:import_dev.z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),SettingsSchema=import_dev2.z.object({cors:import_dev2.z.union([import_dev2.z.boolean(),CorsOptionsSchema]).describe("CORS configuration: false = disabled, true = allow all origins, object = custom configuration").optional(),timeout:import_dev2.z.number().int().positive().max(54e4).describe("Request timeout in milliseconds (max: 540000 for GCP)").optional()}),settings=(0,import_dev3.zodToSchema)(SettingsSchema),examples_exports={};__export(examples_exports,{env:()=>env_exports});var env_exports={};__export(env_exports,{push:()=>push});var createMockElbFn=()=>()=>Promise.resolve({ok:!0,successful:[],queued:[],failed:[]}),noopFn=()=>{},noopLogger={error:noopFn,info:noopFn,debug:noopFn,throw:message=>{throw"string"==typeof message?new Error(message):message},scope:()=>noopLogger},push={get push(){return createMockElbFn()},get command(){return createMockElbFn()},get elb(){return createMockElbFn()},logger:noopLogger},DEFAULT_SETTINGS={cors:!0,timeout:3e4},sourceCloudFunction=async(config={},env)=>{const{push:envPush}=env,settings2={...DEFAULT_SETTINGS,...config.settings||{}};return{type:"cloudfunction",config:{...config,settings:settings2},push:async(req,res)=>{try{if(function(res,corsOptions){if(corsOptions)if(!0===corsOptions)res.set("Access-Control-Allow-Origin","*"),res.set("Access-Control-Allow-Methods","POST, OPTIONS"),res.set("Access-Control-Allow-Headers","Content-Type, Authorization"),res.set("Access-Control-Max-Age","3600");else{if(corsOptions.origin){const origin=Array.isArray(corsOptions.origin)?corsOptions.origin.join(", "):corsOptions.origin;res.set("Access-Control-Allow-Origin",origin)}corsOptions.methods&&res.set("Access-Control-Allow-Methods",corsOptions.methods.join(", ")),corsOptions.headers&&res.set("Access-Control-Allow-Headers",corsOptions.headers.join(", ")),corsOptions.credentials&&res.set("Access-Control-Allow-Credentials","true"),void 0!==corsOptions.maxAge&&res.set("Access-Control-Max-Age",corsOptions.maxAge.toString())}}(res,settings2.cors||!1),"OPTIONS"===req.method)return void res.status(204).send();if("POST"!==req.method)return void res.status(405).json({success:!1,error:"Method not allowed. Use POST."});if(!req.body)return void res.status(400).json({success:!1,error:"Request body is required"});const body=req.body;if(function(body){return"event"in body&&"string"==typeof body.event}(body)){const result=await async function(eventReq,push2){var _a;try{const result=await push2({name:eventReq.event,data:eventReq.data||{},context:eventReq.context,user:eventReq.user,globals:eventReq.globals,consent:eventReq.consent});return{id:null==(_a=null==result?void 0:result.event)?void 0:_a.id}}catch(error){return{error:error instanceof Error?error.message:"Unknown error"}}}(body,envPush);result.error?res.status(400).json({success:!1,error:result.error}):res.status(200).json({success:!0,id:result.id})}else res.status(400).json({success:!1,error:"Invalid request format. Expected event object."})}catch(error){res.status(500).json({success:!1,error:error instanceof Error?error.message:"Internal server error"})}}}},cloudfunction_default=sourceCloudFunction;//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var __defProp=Object.defineProperty,__export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})};var types_exports={},schemas_exports={};__export(schemas_exports,{CorsOptionsSchema:()=>CorsOptionsSchema,CorsOrigin:()=>CorsOrigin,HttpMethod:()=>HttpMethod,SettingsSchema:()=>SettingsSchema,settings:()=>settings});import{zodToSchema}from"@walkeros/core/dev";import{z as z2}from"@walkeros/core/dev";import{z}from"@walkeros/core/dev";var HttpMethod=z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),CorsOrigin=z.union([z.string(),z.array(z.string()),z.literal("*")]),CorsOptionsSchema=z.object({origin:CorsOrigin.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:z.array(HttpMethod).describe("Allowed HTTP methods").optional(),headers:z.array(z.string()).describe("Allowed request headers").optional(),credentials:z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),SettingsSchema=z2.object({cors:z2.union([z2.boolean(),CorsOptionsSchema]).describe("CORS configuration: false = disabled, true = allow all origins, object = custom configuration").optional(),timeout:z2.number().int().positive().max(54e4).describe("Request timeout in milliseconds (max: 540000 for GCP)").optional()}),settings=zodToSchema(SettingsSchema),examples_exports={};__export(examples_exports,{env:()=>env_exports});var env_exports={};__export(env_exports,{push:()=>push});var createMockElbFn=()=>()=>Promise.resolve({ok:!0,successful:[],queued:[],failed:[]}),noopFn=()=>{},noopLogger={error:noopFn,info:noopFn,debug:noopFn,throw:message=>{throw"string"==typeof message?new Error(message):message},scope:()=>noopLogger},push={get push(){return createMockElbFn()},get command(){return createMockElbFn()},get elb(){return createMockElbFn()},logger:noopLogger},DEFAULT_SETTINGS={cors:!0,timeout:3e4},cloudfunction_default=async(config={},env)=>{const{push:envPush}=env,settings2={...DEFAULT_SETTINGS,...config.settings||{}};return{type:"cloudfunction",config:{...config,settings:settings2},push:async(req,res)=>{try{if(function(res,corsOptions){if(corsOptions)if(!0===corsOptions)res.set("Access-Control-Allow-Origin","*"),res.set("Access-Control-Allow-Methods","POST, OPTIONS"),res.set("Access-Control-Allow-Headers","Content-Type, Authorization"),res.set("Access-Control-Max-Age","3600");else{if(corsOptions.origin){const origin=Array.isArray(corsOptions.origin)?corsOptions.origin.join(", "):corsOptions.origin;res.set("Access-Control-Allow-Origin",origin)}corsOptions.methods&&res.set("Access-Control-Allow-Methods",corsOptions.methods.join(", ")),corsOptions.headers&&res.set("Access-Control-Allow-Headers",corsOptions.headers.join(", ")),corsOptions.credentials&&res.set("Access-Control-Allow-Credentials","true"),void 0!==corsOptions.maxAge&&res.set("Access-Control-Max-Age",corsOptions.maxAge.toString())}}(res,settings2.cors||!1),"OPTIONS"===req.method)return void res.status(204).send();if("POST"!==req.method)return void res.status(405).json({success:!1,error:"Method not allowed. Use POST."});if(!req.body)return void res.status(400).json({success:!1,error:"Request body is required"});const body=req.body;if(function(body){return"event"in body&&"string"==typeof body.event}(body)){const result=await async function(eventReq,push2){var _a;try{const result=await push2({name:eventReq.event,data:eventReq.data||{},context:eventReq.context,user:eventReq.user,globals:eventReq.globals,consent:eventReq.consent});return{id:null==(_a=null==result?void 0:result.event)?void 0:_a.id}}catch(error){return{error:error instanceof Error?error.message:"Unknown error"}}}(body,envPush);result.error?res.status(400).json({success:!1,error:result.error}):res.status(200).json({success:!0,id:result.id})}else res.status(400).json({success:!1,error:"Invalid request format. Expected event object."})}catch(error){res.status(500).json({success:!1,error:error instanceof Error?error.message:"Internal server error"})}}}};export{types_exports as SourceCloudFunction,examples_exports as examples,schemas_exports as schemas,cloudfunction_default as sourceCloudFunction};//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/server-source-gcp",
|
|
3
3
|
"description": "Google Cloud Platform server sources for walkerOS (Cloud Functions)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1-next.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"update": "npx npm-check-updates -u && npm update"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@walkeros/core": "0.
|
|
21
|
+
"@walkeros/core": "0.5.1-next.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@google-cloud/functions-framework": "^3.0.0"
|