Giter VIP home page Giter VIP logo

Comments (9)

sjaakiejj avatar sjaakiejj commented on May 29, 2024 1

I've spent some time updating the PR with @bracki's work and migrating the tests over to typescript as well. I'm going to see if I can get it to communicate with my locally running spicedb instance and make sure the tests pass, then I'll update the PR

Screen Shot 2021-10-22 at 08 50 01

Screen Shot 2021-10-22 at 08 50 16

from authzed-node.

bracki avatar bracki commented on May 29, 2024

@sjaakiejj Would you mind sharing the index.d.ts file you created?

from authzed-node.

sjaakiejj avatar sjaakiejj commented on May 29, 2024

@bracki I'll do you one better - opened #11 to setup typescript as part of the repository

from authzed-node.

bracki avatar bracki commented on May 29, 2024

What I settled for now is the following:

Edit the buf.gen.yaml to look like this:

#!/usr/bin/env -S buf generate buf.build/authzed/api:7a18d413329a4f4fb0c4237afb640e8e --template
---
version: "v1"
  # The plugins to run.
plugins:

    # The name of the plugin.
    # Required.
    # By default, buf generate will look for a binary named protoc-gen-NAME on your $PATH.
  - name: ts

    # The the relative output directory.
    # Required.
    out: gen/ts

    # See "available plugin parameters"
    # https://github.com/timostamm/protobuf-ts/blob/master/MANUAL.md#the-protoc-plugin
    opt: generate_dependencies,long_type_string

    # The custom path to the plugin binary, if not protoc-gen-NAME on your $PATH.
    # Assuming you have installed @protobuf-ts/plugin in the working directory:
    path: ./node_modules/@protobuf-ts/plugin/bin/protoc-gen-ts

Run buf generate buf.build/authzed/api:7a18d413329a4f4fb0c4237afb640e8e --template buf.gen.yaml.
Copy the stuff from gen/ts.
Use it like this:

import * as grpc from '@grpc/grpc-js';
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
import { PermissionsServiceClient } from '../authzed/authzed/api/v1/permission_service.client';

function createClientCreds(token: string, insecure = false): grpc.ChannelCredentials {
  const metadata = new grpc.Metadata();
  metadata.set('authorization', 'Bearer ' + token);

  const creds = [];
  if (!insecure) {
    creds.push(grpc.credentials.createFromMetadataGenerator((_, callback) => {
      callback(null, metadata);
    }));
  }

  return grpc.credentials.combineChannelCredentials(
    insecure ? grpc.credentials.createInsecure() : grpc.credentials.createSsl(),
    ...creds,
  );
}

export function createPermissionsServiceClient(token: string): PermissionsServiceClient {
  return new PermissionsServiceClient(new GrpcTransport({
    host: 'grpc.authzed.com:443',
    channelCredentials: createClientCreds(token),
  }));
}

from authzed-node.

josephschorr avatar josephschorr commented on May 29, 2024

@bracki @sjaakiejj The Typescript generated proto code looks a lot nicer than the JS; would you guys be open to collaborating on @sjaakiejj's PR (#11) or a followup to change the client library to use the TS generated types?

from authzed-node.

josephschorr avatar josephschorr commented on May 29, 2024

Also @bracki @sjaakiejj If you guys want to discuss in more detail, we also have the Discord development channel for live discussions: https://discord.com/invite/jTysUaxXzM

from authzed-node.

josephschorr avatar josephschorr commented on May 29, 2024

@sjaakiejj Looks great. I'd recommend testing with v1 API

from authzed-node.

sjaakiejj avatar sjaakiejj commented on May 29, 2024

The PR is now ready for review - do you have any documentation or in particular, examples on how to use the v1 api?

from authzed-node.

josephschorr avatar josephschorr commented on May 29, 2024

@sjaakiejj V1 docs can be found here: https://buf.build/authzed/api/docs/main/authzed.api.v1 and we have some examples using Python here: https://github.com/authzed/authzed-py/tree/main/examples/v1

from authzed-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.