Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish an NPM package #432

Closed
caesarsol opened this issue May 3, 2018 · 7 comments
Closed

Publish an NPM package #432

caesarsol opened this issue May 3, 2018 · 7 comments

Comments

@caesarsol
Copy link

Hi, is this project scheduled to be published as an NPM package?

@Offirmo
Copy link

Offirmo commented May 9, 2018

It should. That's the established way to do it.

@StevenEWright

This comment has been minimized.

@zeusttu
Copy link

zeusttu commented Aug 23, 2018

It is possible to npm install gapi. If I am not mistaken, this will install https://github.com/phated/node-gapi, which saw its latest commit in 2012 and is marked on Github by its author as no longer maintained. I think there really needs to be an official package, even if just because otherwise people will mistakenly think this incredibly outdated one is the official one.
On the other hand, it looks like that one is at least suited for non-browser clients running NodeJS. The library as linked to in the samples of this repository (the actual library itself is not even here, only a placeholder Javascript file) is not; it relies heavily on the window and document variables that are defined by default in a browser. So that would be an issue if publishing to a place mostly aimed at NodeJS devs.

@zeusttu
Copy link

zeusttu commented Aug 31, 2018

The library referenced by StevenEWright seems to be Google's official API client for NodeJS. It's not a perfect copy of this library; class hierarchies and call signatures differ pretty strongly from this library's. Its documentation is also challenging to figure out, particularly as it lacks examples. On the plus side, it has submodules for specific libraries, which this library does not have. It has the same capabilities as this library (apart from the fact that this library only works in browsers and the Node library also works in Node), is reasonably intuitive and logical to use and works well as far as I can tell. It is probably the closest thing Google will ever make to a Node-compatible and NPM-installable version of this library. The downvotes look undeserved as far as I can tell, and I am curious as to their motivation.

@grant
Copy link
Contributor

grant commented Nov 2, 2018

I've look at this. With the way the client is written, it's impossible to make the client public without a full rewrite. The gapi/client uses Google-internal tools in lots of places (probably due to it's age).

At best, I could make an effort to mirror a few read-only files that would have the internal comments stripped.

@Maxim-Mazurok
Copy link

Maxim-Mazurok commented Sep 12, 2019

@grant it might be helpful, can you share those files?

I'm trying to make Google Sheets API for JavaScript more TypeScript-friendly: DefinitelyTyped/DefinitelyTyped#37847

And I'm having issues with POST requests, such as batchUpdate.
It uses request parameter in the discovery docs to define POST request body.

The problem is that I'm not sure how JavaScript library expects this parameter.
Both approaches work:

// NodeJS docs example
batchUpdate({
  spreadsheetId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  resource: {
    requests: [  ],
  },
});
// JavaScript docs example
batchUpdate({
  spreadsheetId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}, {
  requests: [  ],
});

I've found that NodJS library uses this to get check request body:

const resource = params.requestBody ? params.requestBody : params.resource;

And now I wonder what are valid ways to pass request body in JavaScript library. I want to know the implementation to define all valid ways of passing the request body.

I'll try to look into minified sources, but it's quite challenging.
So, any original files will be of great help :)

UPDATE:
I think that I have an answer now, after debugging JavaScript library.
Here's the simplified version of the library code (at least, how I understood it):

// over-simplified version
var prepareRequest = function (
  currentRequestSchema, // docs discovery batchUpdate info
  commonRequestSchema, // docs discovery common info
  arg1, // batchUpdate first argument
  arg2, // batchUpdate second argument
) {
  let body;
  // ...
  arg1 = deleteAllKnownParameters(arg1, currentRequestSchema.parameters, commonRequestSchema.parameters); // extracts all known parameters from arg1 and leaves only unknown ones
  // ...
  if (
    Object.keys(arg1).length == 1 // if arg1 has exactly one unknown property
    && arg1.hasOwnProperty('resource') // and this property is "resource"
  ) {
    body = arg1.resource; // use it as a request body
  }

  if (body == null) {
    body = arg2; // if arg1 was null, use second argument
  }
};

So, basically both approaches are supported by the library. And I can't find any other approach (like using requestBody in NodeJS lib).
Hopefully, it'll be helpful to anybody.

@sergentj
Copy link

Hi there,

Closing this out as won't fix, because we do not plan to support an NPM package for gapi in its current form. For posterity:

As Grant stated above we can't easily support a NPM package for gapi because it's designed to be dynamically loaded via its own loading mechanism.

We do have a few other related libraries available via NPM, and if they support your use cases they are likely a better fit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants